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

Fantasy Land compatibility? #114

Closed
wants to merge 14 commits into from

Conversation

apaleslimghost
Copy link
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?

@apaleslimghost
Copy link
Collaborator Author

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?

@apaleslimghost
Copy link
Collaborator Author

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

@apaleslimghost
Copy link
Collaborator Author

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
Copy link
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.

@apaleslimghost
Copy link
Collaborator Author

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

@LewisJEllis
Copy link
Collaborator

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

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

@apaleslimghost
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
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?

@apaleslimghost
Copy link
Collaborator Author

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

@apaleslimghost
Copy link
Collaborator Author

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

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

@apaleslimghost
Copy link
Collaborator Author

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.

@svozza
Copy link
Collaborator

svozza commented Oct 31, 2018

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

@amsross
Copy link
Contributor

amsross commented Oct 31, 2018

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

@svozza
Copy link
Collaborator

svozza commented Oct 31, 2018

Cool, I'll close then.

@svozza svozza closed this Oct 31, 2018
@apaleslimghost apaleslimghost deleted the fantasy branch October 31, 2018 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants