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

Option.of is non-parametric #146

Open
puffnfresh opened this issue Dec 4, 2018 · 4 comments
Open

Option.of is non-parametric #146

puffnfresh opened this issue Dec 4, 2018 · 4 comments

Comments

@puffnfresh
Copy link

You can't pass null or undefined to Option.of. This is super surprising, incompatible with Fantasy Land and breaks the monad and applicative laws.

@alexandru
Copy link
Member

alexandru commented Dec 4, 2018

@puffnfresh the static Option.of is not return.

In the actual Applicative instance (for both Fantasy Land and static-land) Option.pure is being used, which does not have special treatment for null.

The naming "of" might be unfortunate, but it is very popular in the JS ecosystem and the protocol for FL is describing it with a prefix and the FL spec is respected.

Do you think that's not ok?

@puffnfresh
Copy link
Author

Array.of doesn't violate things in the same way, e.g. Arrray.of(null) == [ null ]

I would argue that there's no precedent for this particular behaviour in the "JS ecosystem" and that Fantasy Land specifically sets a precedent that .of is meant to be parametric.

@alexandru
Copy link
Member

@puffnfresh I was under the impression that the naming matters only in the context of the FL protocol.

For a user familiar with the FL naming however, I'm sure it is annoying. So I agree with you.

Alignment with the naming in FL has been on my mind. As you can see, I preferred flatMap to chain or tailRecM to chainRec among others. Not a very fortunate choice I now realize.

So I would like to change the naming. Unfortunately right now I'm busy with my Scala projects, but hopefully I'll get to it.

If in the meantime if somebody wants to send a PR, just as a note, Option is not the only one with an "of" that's not the Applicative constructor, so the change needs to be across the board.

@puffnfresh thanks for opening the issue. In the meantime if you're in need, use Option.pure.

@puffnfresh
Copy link
Author

Thanks @alexandru

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

2 participants