Skip to content

Instantly share code, notes, and snippets.

@justinvdm
Created December 31, 2017 12:34
Show Gist options
  • Select an option

  • Save justinvdm/0065303737829a73a601d249e7a61fa6 to your computer and use it in GitHub Desktop.

Select an option

Save justinvdm/0065303737829a73a601d249e7a61fa6 to your computer and use it in GitHub Desktop.
// @flow
type ContFn<A, B> = <C>(A, B => C) => C;
const sqr = <R>(v: number, ret: number => R): R => ret(v * v);
const dbl = <R>(v: number, ret: number => R): R => ret(v * 2);
const pipe = <A, B, C>(fn1: ContFn<A, B>, fn2: ContFn<B, C>): ContFn<A, C> =>
<D>(v: A, ret: C => D): D => fn1(v, (res: B) => fn2(res, ret));
const fn = pipe(sqr, dbl);
fn(21, console.log);
[ignore]
[include]
[libs]
[lints]
[options]
[strict]
{
"name": "flow-continuation-passing",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"babylon": {
"version": "6.18.0",
"resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
"integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==",
"dev": true
},
"flow-bin": {
"version": "0.62.0",
"resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.62.0.tgz",
"integrity": "sha1-FLymaabj+VwLwMLR61XsTpjLHYM=",
"dev": true
},
"flow-remove-types": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/flow-remove-types/-/flow-remove-types-1.2.3.tgz",
"integrity": "sha512-ypq/U3V+t9atYiOuSJd40tekCra03EHKoRsiK/wXGrsZimuum0kdwVY7Yv0HTaoXgHW1WiayomYd+Q3kkvPl9Q==",
"dev": true,
"requires": {
"babylon": "6.18.0",
"vlq": "0.2.3"
}
},
"vlq": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.3.tgz",
"integrity": "sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==",
"dev": true
}
}
}
{
"name": "flow-continuation-passing",
"version": "1.0.0",
"description": "",
"main": "+flow-continuation-passing.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"flow-bin": "^0.62.0",
"flow-remove-types": "^1.2.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment