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

Maybe as a Semigroup? #122

Closed
i-am-tom opened this issue Sep 4, 2016 · 7 comments
Closed

Maybe as a Semigroup? #122

i-am-tom opened this issue Sep 4, 2016 · 7 comments

Comments

@i-am-tom
Copy link
Contributor

i-am-tom commented Sep 4, 2016

Hello!

Firstly, this project is great, and I've been playing with it for a few weeks. I have to ask, though: is there a reason why Maybe doesn't have a concat method defined? As I see it, the concatenation would work like this:

Nothing `concat` Nothing = Nothing
Nothing `concat` x = x
x `concat` Nothing = x
(Just x) `concat` (Just y) = Just (x `concat` y)

I'm more than happy to submit the PR if this sounds reasonable - just thought I'd double check in case I'd missed something obvious :)

@davidchambers
Copy link
Member

That's the way S.Maybe#concat is defined.

There's significant overlap between ramda-fantasy and Sanctuary. There's been talk of merging the two projects, in #105 and perhaps in other threads, to avoid further duplication of effort.

I imagine a pull request to define Maybe#concat would be accepted, particularly since what you're proposing is compatible with Sanctuary and would thus not be a source of conflict if and when we merge the projects. :)

@buzzdecafe
Copy link
Member

what @davidchambers said. i'd be happy to see a pr on this.

@TheLudd
Copy link
Contributor

TheLudd commented Sep 5, 2016

Are the middle cases valid?

Nothing `concat` x = x
x `concat` Nothing = x

Should it not be like this?

Nothing `concat` (Just x) = (Just x)
(Just x) `concat` Nothing = (Just x)

@i-am-tom
Copy link
Contributor Author

i-am-tom commented Sep 5, 2016

Would they not both achieve the same results? Either way, it was just a brief explanation :)

I should have a PR ready by the end of the day!

@TheLudd
Copy link
Contributor

TheLudd commented Sep 5, 2016

I am saying that Nothingconcatx = x violates the contract unless x is an instance of Maybe.

concat must return a value of the same Semigroup.

https://github.com/fantasyland/fantasy-land#semigroup

@i-am-tom
Copy link
Contributor Author

i-am-tom commented Sep 5, 2016

Ah, beg your pardon. What I was writing was meant to look more like the instance implementation for a Maybe type in Haskell. Still, as long as the idea is otherwise sound, I'll press on :)

@i-am-tom
Copy link
Contributor Author

i-am-tom commented Oct 1, 2016

Closing - PR's at #123 !

@i-am-tom i-am-tom closed this as completed Oct 1, 2016
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

No branches or pull requests

4 participants