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

More friendly aliases? #1576

Closed
entropitor opened this issue Sep 6, 2021 · 5 comments
Closed

More friendly aliases? #1576

entropitor opened this issue Sep 6, 2021 · 5 comments

Comments

@entropitor
Copy link

🚀 Feature request

I think fp-ts is an awesome library but the name of the functions is not always:

  • the most friendly for newcomers to fp
  • in line with the JS ecosystem

Current Behavior

either.chain

Desired Behavior

// More in line with ecosystem:
either.flatMap


// More friendly to newcomers (e.g. see rust API's)
either.andThen
// The above is also more in line with 
either.orElse

Suggested Solution

Add a bunch of aliases to make it more beginner friendly and potentially deprecate the old ones (and remove in v3) or ship both

Who does this impact? Who is this for?

This will help with beginners and spreading adoption of fp-ts. In my team, we love fp-ts but we fear it can make the codebase harder to understand, especially because the names are very academic / haskelly and are not self-evident in what they do.

Describe alternatives you've considered

  • Create own package with aliases
  • Write better documentation

If you are open to it, I'm happy to help in picking better names. I just gave one example but I think there are others.

@samhh
Copy link
Contributor

samhh commented Sep 6, 2021

chain is very fundamental to the library and I think any benefit in renaming it would be outweighed by the cost of deprecation to everyone who's already written code against that function name.

Function aliases would in a sense fragment the ecosystem and I'm not sure it makes things any less confusing; the inevitable question that follows from a beginner is "what's the difference between these?".

Additionally, the adherence in some cases (though not with chain) to Haskell idioms can be a win for anyone coming from a functional language or anyone going to or otherwise learning a functional language.

Sorry to be so negative - how to make the library beginner-friendly is certainly something that deserves attention, and I've never liked this naming choice either. Just my two cents on this specifically.

@entropitor
Copy link
Author

I think those are very fair points!

I'm open to other alternatives as well, where e.g. in the documentation we add "common alternatives" so if you hover / if you check out the documentation, you also see other names you might be more used to to help understand what a function does. This would also help with transitioning to other languages.

I get your point about more fp languages but on the other hand, every language / library seems to use different names, so I'm not sure if that's 100% fair. I think one of the reasons rust doesn't seem to have a problem with map and andThen for their result type, is because it's just understandable as to what the function does. While with chain and bind, it's not as clear (IMO)

@samhh
Copy link
Contributor

samhh commented Sep 6, 2021

Some way to find chain by searching for "flatMap" for example in the docs would be handy, likewise as you've said a "this is also sometimes known by" line. 👍

@entropitor
Copy link
Author

What could be really cool is on top of that to have typescript definitions for flatMap, andThen, ... and just make them obsolete / deprecated and not actually implement them. And then just in their docs mention "use chain instead" or something. That way, you can even in your editor type what you are used to and get reminded what the actual name should be.

@gcanti
Copy link
Owner

gcanti commented Apr 20, 2023

#1849

@gcanti gcanti closed this as completed Apr 20, 2023
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

3 participants