Last active
December 10, 2017 18:08
-
-
Save mofas/006d4884e619d7ef8bb9b1e79e6153fd to your computer and use it in GitHub Desktop.
Implement set in pure functional way
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
const empty = () => y => window.Error("not found error"); | |
const extendSet = (y, val, set) => x => x === y ? val : set(x); | |
const setA = extendSet('a', 3, empty()); | |
setA('a'); // 3 | |
setA('b'); // not fuond error | |
const setA2 = extendSet('b', 4, setA); | |
setA2('a'); // 3 | |
setA2('b'); // 4 | |
const setA3 = extendSet('a', 42, setA2); | |
setA3('a'); // 42 | |
setA3('b'); // 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment