Fantasy Land compatibility? #114

Open
wants to merge 14 commits into
from

Projects

None yet

4 participants

@quarterto
Collaborator

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
Collaborator

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
Collaborator

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

@quarterto quarterto self-assigned this Nov 25, 2014
@quarterto
Collaborator

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
Collaborator

+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
Collaborator

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

@LewisJEllis
Collaborator

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

@jeromew
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
Collaborator

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
Collaborator

Good call :)

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

@vqvu
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
Collaborator

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

@quarterto
Collaborator

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

@jeromew
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
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.

@quarterto
Collaborator

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 in ramda/ramda Apr 21, 2015
Closed

Highland.js Integration #1037

This was referenced Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment