https://github.com/pfgray/babel-plugin-monadic-do
Monads, Do style
https://github.com/pfgray/babel-plugin-monadic-do
Last synced: 2 months ago
JSON representation
Monads, Do style
- Host: GitHub
- URL: https://github.com/pfgray/babel-plugin-monadic-do
- Owner: pfgray
- Created: 2018-10-23T19:19:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T13:54:10.000Z (over 6 years ago)
- Last Synced: 2025-03-18T09:37:47.632Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 38
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
Hijacks `do` expressions with bitwise left shift (`<<`) to implement the `for`/`yield` syntax we all know and :heart: from [scala](https://docs.scala-lang.org/tutorials/FAQ/yield.html).
If you don't like using the tasiest syntax sugar available, then stay away!
However, if you like feeling alive and the taste of the kool-aid they're handing out in fp land, then look no further!
You can turn:
```js
getFoo("/api/foo").chain(foo => {
return getBar("/api/bar").chain(bar => {
const lol = bar.name;
return getBaz("/api/baz/" + lol).map(baz => {
return foo + bar + baz;
});
});
});
```into:
```awesome-sauce
do {
foo << getFoo("/api/foo")
bar << getBar("/api/bar")
const lol = bar.name;
baz << getBaz("/api/baz/" + lol)foo + bar + baz;
}
```Limitations:
1. Top expression _must_ be a 'bind' expression, i.e. `x << y`
2. Last line must be a plain expression (not a bind expression)
3. Coworkers will loathe you when you try to explain monads to them.