https://github.com/aitoroses/babel-plugin-syntax-monadic-comprehensions
https://github.com/aitoroses/babel-plugin-syntax-monadic-comprehensions
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aitoroses/babel-plugin-syntax-monadic-comprehensions
- Owner: aitoroses
- License: mit
- Created: 2018-11-21T07:41:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-21T12:33:40.000Z (over 7 years ago)
- Last Synced: 2025-11-29T03:25:42.857Z (7 months ago)
- Language: JavaScript
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Babel Syntax Monadic For Support
This is a plugin for Babel 7 that is meant to replicate Scala's for comprehension or haskell's do syntax.
## Babel >= 7.x
```json
{
"plugins": [
"babel-plugin-syntax-monadic-comprehensions",
]
}
```
## Installation & Usage
$ npm install --save-dev babel-plugin-syntax-monadic-comprehensions
Add the following line to your .babelrc file:
{
"plugins": ["babel-plugin-syntax-monadic-comprehensions"]
}
This will transform this kind of code:
```
import Identity, { For, Yield } from './Identity'
const comp = For(() => {
const a = Yield(Identity.pure(1))
const b = Yield(Identity.pure(1))
return a + b
})
// => Identity(2)
```
in this code:
```
import { flatMap, map } from "./Identity";
import Identity, { For, Yield } from './Identity';
const comp = flatMap(Identity.pure(1), a => {
return map(Identity.pure(1), b => {
return a + b;
});
});
// => Identity(2)
```
Where Identity is the identity monad instance.
> *note* Assumes that the module from which `For` and `Yield` are imported also export `flatMap` and `map` operators.
## License
MIT (c) 2015