Skip to content
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

Added "do notation" for Maybe, Either, Validation and IO Monads using generators #159

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

sevcsik
Copy link

@sevcsik sevcsik commented Mar 5, 2018

Added a generic doNotation function, which is bound to monads Maybe, Either, Validation and IO as a static do method. This will allow one to have a similar experience as Haskell's do using ES6 generators.

Example:

Maybe.do(function*() {
  var a = yield Maybe.Just(5)
  var b = yield Maybe.Just(1)
  return a+b
}) // => Just(6)

The new library code itself doesn't require ES6, but the unit tests do, thus it was required to drop PhantomJS in favour of headless Chrome for unit tests (PhantomJS is abandoned anyway).

This PR doesn't include TypeScripy bindings yet, as it would require the IterableIterator type which would make the es6 target mandatory.

Fixes #103

@graingert
Copy link

You could use Babel to support phantomjs

@sevcsik
Copy link
Author

sevcsik commented Mar 5, 2018

@graingert, I could, but I find it overkill to introduce a transpiler just to be able to run the unit tests. As PhantomJS has been abandoned, I think it makes more sense to switch to a headless browser.

@sevcsik
Copy link
Author

sevcsik commented Mar 15, 2018

@ulfryk?

@ulfryk
Copy link
Member

ulfryk commented Mar 15, 2018

Sorry guys, don't have too much time lately…
👍 for HEadlessCHrome
👎 for Babel

And what is most important from my point of view, this should be a separate library in @monet/ NPM namespace. And it's source should be written in TS (as we are planning to rewrite monet itself), and lib/ should be transpiled to ES6 in this case. Tests (both for node and browser) should be also written in TS for sake of consistency.

I;ll bootstrap repository for it today/tomorrow ;)

@ulfryk
Copy link
Member

ulfryk commented Jun 4, 2019

@sevcsik - sorry for horrible delay :(

Are you still willing to contribute and make a standalone lib for do ?

@sevcsik
Copy link
Author

sevcsik commented Jun 5, 2019

@ulfryk I did a PoC for Maybe last year. TBH I don't remember how far I got. I didn't end up using Monet in any of my projects so I put this on the backburner.

Here's what I got: https://github.com/sevcsik/monet-do/blob/master/src/index.ts

If you see potential in it I'd be more than happy to continue. I'll write some tests to see if it works like the JS version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support function* generators as a sort of do notation.
3 participants