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

Implement FantasyLand ChainRec #125

Merged
merged 11 commits into from
Sep 16, 2016
Merged

Implement FantasyLand ChainRec #125

merged 11 commits into from
Sep 16, 2016

Conversation

safareli
Copy link
Contributor

@safareli safareli commented Sep 8, 2016

Implemented ChainRec for:

  • Either
  • Identity
  • Maybe
  • Future
  • IO

Not implemented for:

  • Reader, ReaderT
  • State, StateT

(As I don't quite understand Transformers, may create other PR when I get them)

Fixes #124

If feature is not resolved synchronously then old implementation produces
strange fails. this way we could express equality of async Features.
Also use deepEqual instead of equal.
@safareli
Copy link
Contributor Author

Hey @buzzdecafe now you can do a review 🎉

@buzzdecafe
Copy link
Member

thanks -- there's a lot for me to digest here. I don't know how much time I have to review this weekend. I hope some other contributors may be able to have a look?

function(v) {
return v;
},
f(util.chainRecNext, util.chainRecDone, state.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make use of the existing Either to handle next and done here.

I think something like this should work:

Either.chainRec = Either.prototype.chainRec = function(f, i) {
  var updateState = Either.either(
    compose(Right, Left),
    Either.either(compose(Left, Right), compose(Right, Right))
  );
  var state = Left(Right(i));
  while (Either.isLeft(state)) {
    state = updateState(f(Left, Right, state.value.value));
  }
  return state.value;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated my implementation but I think it's better to use custom structure for representing state instead of Either and it's also simpler to understand.

@scott-christopher
Copy link
Member

This is great work @safareli! I can take a look into adding support for State/T and Reader/T.

@safareli
Copy link
Contributor Author

@scott-christopher thanks, that would be awesome!

@buzzdecafe
Copy link
Member

apart from some detail-y stuff in the tests, LGTM

@buzzdecafe buzzdecafe closed this Sep 14, 2016
@safareli
Copy link
Contributor Author

@buzzdecafe I think you have accidentally closed it :p

@buzzdecafe buzzdecafe reopened this Sep 15, 2016
@buzzdecafe
Copy link
Member

oops, sorry. it's been a long few days

}, 100000)));
});

it('fail Immediately', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer if these it statements read like English, e.g. it("responds to failure immediately") etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return cTest.equivalence(Future, predicate, done, next, initial);
});

it('sync and async Futures', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a more descriptive it here would be nice. what does this test prove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, it tests if it works when mixing sync and async futures

@buzzdecafe
Copy link
Member

🐪

@buzzdecafe buzzdecafe merged commit 8675e80 into ramda:master Sep 16, 2016
@safareli safareli deleted the chainrec branch September 16, 2016 12:46
@safareli
Copy link
Contributor Author

sweet 🍓

@safareli
Copy link
Contributor Author

Could we bump version?

@scott-christopher
Copy link
Member

v0.7.0 has been published.

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.

3 participants