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

Add appliedTo and chain aliases #129

Closed
NickSeagull opened this issue Dec 3, 2018 · 2 comments
Closed

Add appliedTo and chain aliases #129

NickSeagull opened this issue Dec 3, 2018 · 2 comments
Labels
good first issue Good for newcomers new Bring something new into library (add function or type or interface)

Comments

@NickSeagull
Copy link

NickSeagull commented Dec 3, 2018

Hi 👋

I wanted to request the addition of the following function aliases:

appliedTo = (<*>)

and

chain = (=<<)

The reason behind this, is that I found them much easier to understand for newcomers, and they are much better in my experience with teaching Haskell, as one can resemble fluent APIs from other languages with them:

Just(drop 1)
& appliedTo (Just [1,2,3])
& chain head

vs

(Just [1,2,3] <*> Just (drop 1)) >>= head

I really love relude , I really wish it becomes the standard for preludes out there. For me it is always the prelude of choice, and would love that it had nice little features like these that make the adoption of Haskell much easier 😊

If this is okay for you, I can work on a PR. Where should these aliases go? 🤔

@vrom911
Copy link
Member

vrom911 commented Dec 3, 2018

@NickSeagull Thanks for such kind words 😊

Regarding your proposal, I think that these functions make perfect sense and should be pretty useful for understanding indeed! I see that appliedTo is not intersecting with any existing common functions. But chain is used quite a lot (I see it in streaming, pipes libraries, and some more as well), probably chained or chainedTo will do? What do you think?

@chshersh
Copy link
Contributor

chshersh commented Dec 3, 2018

@NickSeagull It's so nice to hear kind words about our project 😊

As @vrom911 pointed out, appliedTo is not present on Hackage, so it's okay to take this name. I guess Relude.Applicative would be the best place for this function 👍 Often <*> is called apply (or spaceship or star cyclops) but looks like apply is taken for & in the ecosystem:

Regarding chain: this name is much more popular and looks more generic (also often used not only in streaming libraries, but also in parser-combinator libraries). So I tend to vote more for chained or chainedTo (for naming consistency). Usually >>= is called andThen but from your examples I see that you defined natural language aliases for flipped versions of >>= and <*>. Though, with human-readable names we indeed can write more beginner-friendly code:

Just ["garbage", "2"] `appliedTo` Just (drop 1) `chainedTo` viaNonEmpty head `chainedTo` readMaybe

(or you can replace chainedTo with andThen but I kinda like chainedTo)

I guess chainedTo can go to Relude.Monad module. Also, since we care a lot about good documentation, it would be really nice to see good Haddock with doctest examples for both functions.

@chshersh chshersh added good first issue Good for newcomers new Bring something new into library (add function or type or interface) labels Dec 21, 2018
@chshersh chshersh added this to the v0.5.0: Improvements milestone Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers new Bring something new into library (add function or type or interface)
Projects
None yet
Development

No branches or pull requests

3 participants