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

Fantasy Land compatibility? #114

Closed
wants to merge 14 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@quarterto
Collaborator

quarterto commented Jan 8, 2015

Fantasy Land is a specification for algebraic Javascript structures. Highland streams almost implement Monoid and Monad. What we'd need to change to be fully compatible:

  1. Alias flatMap to chain
  2. Add _.of as a shortcut for λ x → _([x])
  3. Add _.empty as a shortcut for λ → _([])
  4. Add ap, to apply each of a stream of functions to each of a stream of values.
  5. (Nice to have) add tests to ensure we satisfy the laws.

What are people's opinions on this?

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Jul 24, 2014

On 4, the standard implementation of ap for a Monad is usually:

Thing.prototype.ap = function(xs) {
  return this.chain(function(f) {
    return xs.map(f);
  });
};

Of course, we can't do this directly, as xs would be consumed multiple times. Is it correct to fork xs in this case?

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Jul 24, 2014

On 5, Fantasy-check can verify Fantasy Land laws, and is NodeUnit compatible.

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Nov 25, 2014

I'm fairly keen to see this happen, would enable all kinds of cool interop with e.g. sweet.js macros for do-notation. Property-based testing would also give us a bit more confidence in our tests.

@LewisJEllis

This comment has been minimized.

Collaborator

LewisJEllis commented Nov 25, 2014

+1 on this; I had never heard of Fantasy Land before, but I've certainly picked up on (and appreciated) the similarities between HL streams and monoids/monads.

It would be really cool to formalize it, and having a nodeunit-compatible quickcheck seems too convenient.

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Nov 25, 2014

Found the branch I was working on: https://github.com/quarterto/highland/compare/fantasy

@LewisJEllis

This comment has been minimized.

Collaborator

LewisJEllis commented Jan 2, 2015

Status on this? 3.0.0 seems like a good place to get this out.

@jeromew

This comment has been minimized.

Collaborator

jeromew commented Jan 2, 2015

at this stage we should not add new features to the 3.0.0 branch. We first need to get caolan's approval on the engine rewrite.

The only features that can should be added to 3.0.0 right now are the ones that accepted and commited on 2.x.

otherwise I fear that 3.0.0 will never see the light of day ;-)

2.x and 3.x have already started forking. Maybe this issue can be tagged 3.0.0 and we will make sure it gets done once everybody is ok on the engine rewrite.

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Jan 2, 2015

Current status: I got stuck trying to get Fantasy-check working, and I'm not sure if we can get Applicative to work. I'd be happy to wait for a 3.1 release.

@LewisJEllis

This comment has been minimized.

Collaborator

LewisJEllis commented Jan 2, 2015

Good call :)

I checked in on the 3.0.0 issue instead and made that label.

@LewisJEllis LewisJEllis added the 3.x label Jan 2, 2015

@vqvu

This comment has been minimized.

Collaborator

vqvu commented Jan 3, 2015

@quarterto couldn't we just implement ap in a way similar to

ap = function (xs) {
    var self = this;
    return xs.collect().flatMap(function (array) {
        return self.chain(function (f) {
            return _(array).map(f);
        });
    });
}

but with smarter handling for the infinite xs case?

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Jan 6, 2015

Quick update on this, for fantasy-check to work there needs to be a synchronous way of getting stream contents, any ideas @vqvu?

@quarterto

This comment has been minimized.

Collaborator

quarterto commented Jan 6, 2015

Also, since this is planned for post-3.0 should I rebase it on the 3.0.0 branch?

@jeromew

This comment has been minimized.

Collaborator

jeromew commented Jan 6, 2015

@quarterto this gist may help you regarding a 'synchronous way of getting stream contents' - https://gist.github.com/vqvu/a7838e456783432a2e45

I suggest you wait a bit before rebasing. We don't know yet how 3.0.0 is going to be rebased/merged over the next 2.x

@vqvu

This comment has been minimized.

Collaborator

vqvu commented Jan 6, 2015

@quarterto I'm not too familiar with fantasy-check, but can't you just use an ArrayStream when testing? That would make everything synchronous.

Matt Brennan
@quarterto

This comment has been minimized.

Collaborator

quarterto commented Jan 8, 2015

Here's the work in progress, I'll flesh out the tests, remove the non-fantasy-check ones I added and implement ap, then it should be ready to go. Think it makes sense to leave this unmerged until 3.0 lands.

@quarterto quarterto referenced this pull request Apr 21, 2015

Closed

Highland.js Integration #1037

Matt Brennan

@vqvu vqvu force-pushed the caolan:master branch from bed3cff to 080c4d3 Jul 8, 2016

@svozza svozza referenced this pull request Aug 5, 2016

Closed

_.of and asyncify #519

@buzzdecafe buzzdecafe referenced this pull request Sep 25, 2016

Merged

fantasy-land@1.0.x #1900

3 of 4 tasks complete
@svozza

This comment has been minimized.

Collaborator

svozza commented Oct 31, 2018

Can this be closed now because of the recent PRs @amsross has done?

@amsross

This comment has been minimized.

Contributor

amsross commented Oct 31, 2018

I would say so. All the mentioned bases are covered in #643, #657, and #658.

@svozza

This comment has been minimized.

Collaborator

svozza commented Oct 31, 2018

Cool, I'll close then.

@svozza svozza closed this Oct 31, 2018

@quarterto quarterto deleted the quarterto:fantasy branch Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment