-
-
Save dimitris-papadimitriou-chr/1d56c61e32d99279a44ecd39e5568535 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
//https://medium.com/@dimpapadim3 | |
var node = (left, value, right) => ({ | |
left: left, | |
value: value, | |
right: right, | |
map: f => node(left.map(f), f(value), right.map(f)), | |
fold: (mempty, mappend) => | |
mappend(mappend(mappend(mempty, left.fold(mempty, mappend)), value), right.fold(mempty, mappend)) | |
}); | |
var leaf = value => ({ | |
value: value, | |
map: f => leaf(f(value)), | |
fold: (acc, mappend) => mappend(acc, value) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment