-
Notifications
You must be signed in to change notification settings - Fork 114
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
support function* generators as a sort of do notation. #103
Comments
@graingert can you give an example of how would you like it to look like ? |
const helloWorld = putStr("Hello")
.flatMap(putStr(" "))
.flatMap(putStr("world!"))
.flatMap(putStr("\n")); const helloWorld = moent.Do(function* () {
yield putStr("Hello");
yield putStr(" ");
yield putStr("world!");
yield putStr("\n");
}); you can also get values out too: const hamSpam = monet.Do(function* () {
const x = yield reader();
const y = x.toLowerCase();
yield putStr(y);
}); |
it would have to crash for monads with more than 1 element. |
sadly it's really slow: https://github.com/pelotom/burrido#caveats |
Despite the limitations, I do think it would be useful for a limited set Monads where there's only one value, like Maybe and Either. Those who want to use it with streams despite the performance penalty can use burrido instead. |
@graingert @sevcsik sorry for not being responsive. This seems to be quite an interesting feature, yet there is still a lot of work to make 'monet' stable and equipped with all needed/requested basic features. So probably it'll not appear in the library in some short time. I'm thinking also how to make it work without crashing lib for ES5 limited environments… Anyway:
PS |
I sketched an implementation for the do notation (unfortunately https://repl.it/@sevcsik/monet-monad-comprehension |
The library itself should only contain the My concern about writing a separate library is about determining the But if we would add it to every monadic type, like |
I agree. Do you know any way to detect that in a generic way? I couldn't think of anything... Of course, we could whitelist monads which are known to work if we only support Monet's monads. |
Opened a PR. I'm yet to figure out how to make the |
No description provided.
The text was updated successfully, but these errors were encountered: