Skip to content

Instantly share code, notes, and snippets.

@mofas
Last active December 10, 2017 18:08
Show Gist options
  • Save mofas/006d4884e619d7ef8bb9b1e79e6153fd to your computer and use it in GitHub Desktop.
Save mofas/006d4884e619d7ef8bb9b1e79e6153fd to your computer and use it in GitHub Desktop.
Implement set in pure functional way
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