Skip to content

Instantly share code, notes, and snippets.

@davidchase
Created January 3, 2017 15:41
Show Gist options
  • Save davidchase/1529f90ea8dee952d748dda1596f7b21 to your computer and use it in GitHub Desktop.
Save davidchase/1529f90ea8dee952d748dda1596f7b21 to your computer and use it in GitHub Desktop.
const Coyo = (f, v) => ({fn: f, val: v})
const id = x => x
const liftCoyo = a => Coyo(id, a)
const fmap = (fn, coyo) => Coyo(compose(fn, coyo.fn), coyo.val)
const lower = coyo => map(coyo.fn, coyo.val)
const bindCoyo = (fn, coyo) => liftCoyo(chain(compose(lower, coyo.fn, fn), coyo.val))
const apCoyo = (f, g) => liftCoyo(ap(lower(f), lower(g)))
apCoyo(liftCoyo([inc, add(10)]), liftCoyo([1,2,3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment