Last active
December 30, 2017 14:58
-
-
Save justinvdm/b6b2d706cfb722dc70185edc9bc960f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| type PipeObjMap<B,C> = <A>(A => B) => (A => C); | |
| const pipeFn = <A,B,C>(fn1: A => B, fn2: B => C): (A => C) => (v: A) => fn2(fn1(v)); | |
| const pipeObj = <Fns: {},B,C>(fns: Fns, fn2: B => C): $ObjMap<Fns, PipeObjMap<B,C>> => { | |
| const res = {}; | |
| for (const k in fns) { | |
| if (fns.hasOwnProperty(k)) { | |
| res[k] = pipeFn(fns[k], fn2); | |
| } | |
| } | |
| return res; | |
| }; | |
| const dbl = (v: number): number => v * 2; | |
| const d = { | |
| a: (v: string): number => +v, | |
| b: (v: number): number => v * 3 | |
| }; | |
| const d2 = pipeObj(d, dbl); | |
| console.log(d2.a('23')); | |
| console.log(d2.b(21)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ignore] | |
| [include] | |
| [libs] | |
| [lints] | |
| [options] | |
| [strict] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "flow-obj-map", | |
| "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 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "flow-obj-map", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "+flow-obj-map.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