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鈥檒l 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

Comments

Projects
None yet
3 participants
@NickSeagull
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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.

@NickSeagull NickSeagull referenced this issue Dec 20, 2018

Merged

Add appliedTo and chainedTo functions #130

6 of 10 tasks complete

@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
You can鈥檛 perform that action at this time.