Skip to content

Instantly share code, notes, and snippets.

This file has been truncated, but you can view the full file.
@kimamula
kimamula / sort.js
Created October 28, 2017 15:46
JavaScript asynchronous sort
/**
* return the mid value among x, y, and z
* @param x
* @param y
* @param z
* @param compare
* @returns {Promise.<*>}
*/
async function getPivot(x, y, z, compare) {
if (await compare(x, y) < 0) {
@kimamula
kimamula / Optional.ts
Last active December 3, 2020 20:12
Implementation of Optional (Maybe) in TypeScript
class Some<A> implements Optional<A> {
constructor(private a: A) {
}
getOrElse(a: A) {
return this.a;
}
map<B>(func: (a: A) => B) {
return Optional(func(this.a));
}
match<B>(cases: {