Skip to content

Instantly share code, notes, and snippets.

View moatorres's full-sized avatar
👋

Moa Torres moatorres

👋
  • 18:42 (UTC -03:00)
View GitHub Profile
@moatorres
moatorres / Identity.js
Last active June 27, 2021 13:50
Identity type in JS/Node (without classes)
export const Identity = (x) => ({
chain: (f) => f(x),
unwrap: () => x,
map: (f) => Identity(f(x)),
inspect: () => `Identity(${x})`,
})
@moatorres
moatorres / List.js
Last active June 27, 2021 13:51
Lazy-list in JS/Node (with ES6 classes)
// a Haskell-like lazy-list
// adapted from this awesome gist: https://gist.github.com/gvergnaud/6e9de8e06ef65e65f18dbd05523c7ca9
export class List {
constructor(generator, length) {
this[Symbol.iterator] = generator
this.length = length
}
// should be private
@moatorres
moatorres / Maybe.d.ts
Last active June 27, 2021 13:51
Maybe monad in JS/Node (with ES6 classes)
type CallbackFunction<T = unknown> = (...params: unknown[]) => T
export class Maybe<T> {
private constructor(private value: T | null) {}
static just<T>(a: any): Maybe<T>
static nothing<T>(): Maybe<T>
static fromValue<T>(value: T | undefined | null): Maybe<T>
isJust(): boolean
isNothing(): boolean
toString(): string
@moatorres
moatorres / Maybe.d.ts
Last active June 27, 2021 13:49
Maybe monad in JS/Node (without classes)
type NotNullOrUndefined = string | number | boolean | symbol | object
interface IMaybe<T> {
type: symbol
has(): boolean
isJust(): boolean
isNothing(): boolean
unwrap(): T | never
map<U>(fn: (value: T) => U): IMaybe<U>
flatMap<U>(fn: (value: T) => U): T
@moatorres
moatorres / .bash_profile.sh
Last active June 27, 2021 13:58
Bash Profile
# @hoxlux/bash
# 🗂 💡 🔑 🔐 🚨 🐙 🌴 🔥 🌈 🥥 🥚 ⏱ 🧰 🧪 🛍 🇬🇧 🇧🇷
alias ga="git add ."
alias gc1="git commit -m 'commit inicial'"
alias gmaster="git switch master"
alias gnext="git switch next"
alias gprod="git switch production"
function parse_git_branch {