-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monad chain does exist now in JS #242
Comments
Hi Laurent, if I’m right chaining promises with |
Hello Laurent, Thanks :)
// Implementation
Array.prototype.chain = function (f) {
return this.reduce((acc, it) => acc.concat(f(it)), [])
}
// Usage
Array.of('cat,dog', 'fish,bird').chain((a) => a.split(',')) // ['cat', 'dog', 'fish', 'bird']
// Contrast to map
Array.of('cat,dog', 'fish,bird').map((a) => a.split(',')) // [['cat', 'dog'], ['fish', 'bird']]
Now I see that |
I don’t know 🤔 Maybe JS was chosen for this repository because it is a lingua franca that everyone knows enough to understand FP concepts implemented in it, whatever your language background is. In the same way arrays-like structures are implemented in most languages and most people know them, unlike promises. |
Hello,
I just wanted to say that flatMap is part of JS and widely supported now :)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
Have a nice day, best regards,
Laurent Lyaudet
The text was updated successfully, but these errors were encountered: