Last active
June 27, 2021 13:50
-
-
Save moatorres/afbcfe91ebc619eb5dfd4ea4c1847fc5 to your computer and use it in GitHub Desktop.
Identity type in JS/Node (without classes)
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
import { Identity } from './Identity' | |
let res = Identity(3) | |
.map((v) => v * 3) | |
.map((v) => v * 3) | |
.map((v) => v * 33) | |
.chain(Identity) | |
console.log(res.map((v) => v - 1).inspect()) // => 'Identity(890)' |
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
export const Identity = (x) => ({ | |
chain: (f) => f(x), | |
unwrap: () => x, | |
map: (f) => Identity(f(x)), | |
inspect: () => `Identity(${x})`, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment