https://github.com/coot/monadicjs
JavaScript monad library with do-notation
https://github.com/coot/monadicjs
functional-programming javascript javascript-monads monad monad-library state-monad
Last synced: about 2 months ago
JSON representation
JavaScript monad library with do-notation
- Host: GitHub
- URL: https://github.com/coot/monadicjs
- Owner: coot
- License: mit
- Created: 2016-10-08T17:21:04.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-17T18:52:19.000Z (almost 9 years ago)
- Last Synced: 2025-07-28T07:44:21.641Z (3 months ago)
- Topics: functional-programming, javascript, javascript-monads, monad, monad-library, state-monad
- Language: JavaScript
- Size: 35.2 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://travis-ci.org/coot/monadicjs)
# Monad library for JavaScript
Monads can be very useful for async IO. They succefully appeared in Haskell.
Haskell provides the `do` notation for executing monads. And this library
ports `do` to JavaScript. Something that looks like this in Haskell```Haskell
do {
fileContent <- readFile "README.md"
putStr fileContent
}
```will look like this in JavaScript:
```JavaScript
const fs = require("fs")
do_(function*() {
const fileContent = yield fs.readFile.bind(null, "README.md")
console.log(fileContent)
})
```Checkout tests how to experiment with it.
You will not be able to code every monad that one can programm in Haskell (like
the list monad), but a lot is possible with this approach. Here is what you
can do in Haskell but not with this library:
```Haskell
do {
x <- [1,2,3]
return (2*x)
} {- [2,4,6] -}
```# Available monads
* [Maybe](https://github.com/coot/monadicjs/blob/master/lib/maybe.js) [Haskell Maybe](https://wiki.haskell.org/Maybe)
* [Either](https://github.com/coot/monadicjs/blob/master/lib/either.js)
* [Promise](https://github.com/coot/monadicjs/blob/master/lib/promise.js)
* [NodeContinuation](https://github.com/coot/monadicjs/blob/master/lib/node-continuation.js) or node callbacks
* [State Monad](https://wiki.haskell.org/State_Monad))# Ideas
* use a (kind of) state monad for [react-redux](https://github.com/reactjs/react-redux) store
* monad transformers
* [react-redux](https://github.com/reactjs/react-redux) store middleware