Skip to content

Instantly share code, notes, and snippets.

View alexandredantas's full-sized avatar

Alexandre Dantas alexandredantas

View GitHub Profile
type Callback<A> = (a: A) => void;
/**
* Delays stuff for ensuring fairness.
*/
export function yieldRunLoop(): Promise<void> {
const fn: (cb: (() => void)) => void = typeof setImmediate !== 'undefined'
? setImmediate
: cb => setTimeout(cb, 0)
return new Promise(fn)
@programaker
programaker / about-variance.scala
Last active August 28, 2019 16:27
Scala: about variance
class Producer[+X](x: X) {
def produce: X = x
}
class Consumer[-X](name: String) {
def consume(x: X): Unit = println(s">>> $name is consuming $x polimorfically")
}
//--------------------------------------
@programaker
programaker / monads-are-monoids-in-the-category-of-endofunctors.txt
Created November 3, 2018 02:57
Monads are Monoids in the Category of Endofunctors
"Monads are Monoids in the Category of Endofunctors"
If you are a functional programmer, you've probably heard this statement before.
To understand it, first we need to understand its component parts:
. Category
. Monoid
. Endofunctor
After this, we will glue those parts together piece by piece to grasp the whole.
@pirate
pirate / parseURLParameters.js
Last active December 15, 2023 07:17
Parse URL query parameters in ES6
function getUrlParams(search) {
const hashes = search.slice(search.indexOf('?') + 1).split('&')
const params = {}
hashes.map(hash => {
const [key, val] = hash.split('=')
params[key] = decodeURIComponent(val)
})
return params
}