Skip to content

Instantly share code, notes, and snippets.

View weidagang's full-sized avatar

Dagang Wei weidagang

  • Bay Area, California
View GitHub Profile
@weidagang
weidagang / free-monad.js
Last active December 21, 2020 08:55 — forked from DrBoolean/free-er.js
Free Monad in JavaScript
// Forked and modified from https://gist.github.com/DrBoolean/34c1d3651d1338b1b187
const daggy = require('daggy')
const compose = (f, g) => x => f(g(x))
const id = x => x
const kleisli_compose = (f, g) => x => f(x).flatMap(g)
//=============FREE=============
const Free = daggy.taggedSum({Suspend: ['x', 'f'], Pure: ['x']})
@weidagang
weidagang / go.js
Created October 27, 2017 14:34 — forked from Gozala/go.js
Go routines for JS
// Utility function for detecting generators.
let isGenerator = x => {
return Function.isGenerator &&
Function.isGenerator.call(x)
}
// Data type represents channel into which values
// can be `put`, or `received` from. Channel is
// very much like queue where reads and writes are
// synchronized via continuation passing.