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

flap should be flipped #1827

Open
samhh opened this issue Jan 25, 2023 · 5 comments
Open

flap should be flipped #1827

samhh opened this issue Jan 25, 2023 · 5 comments
Milestone

Comments

@samhh
Copy link
Contributor

samhh commented Jan 25, 2023

The current type signature of flap is:

Functor f => a -> f (a -> b) -> f b

It would be better if it were:

Functor f => f (a -> b) -> a -> f b

The issue I'm constantly running into with the current shape is that I usually have a in a pipeline and want to bring my own f (a -> b) i.e. it's stopping me from writing pointfree code:

// Current
flow(f, x => A.flap(x)([g, ...etc]), h)

// Desired
flow(f, A.flap([g, ...etc]), h)

The type system isn't capable of allowing flip to handle this.

The proposed signature would also match Haskell:

@gcanti gcanti added this to the 3.0.0 milestone Jan 29, 2023
@imcotton
Copy link
Contributor

But in Haskell (or PureScript) you'd almost be using flap by its infix flavor <@> which matches current curried signature from fp-ts, so that:

Apply a value in a computational context to a value in no context. 1

Footnotes

  1. https://pursuit.purescript.org/packages/purescript-prelude/6.0.1/docs/Data.Functor#v:flap

@samhh
Copy link
Contributor Author

samhh commented Feb 3, 2023

Anecdotally the Haskell codebase I work on most has two usages of flap, one infix/flipped and one not.

I'd be open to other suggestions as this has been a recurrent pain point for me with flap in fp-ts.

Given that with the type system our flip isn't as flexible as in other languages, I wonder if fp-ts should adopt a convention for commonly flipped functions. An example would be fp-ts-std/Array::elemV, which has been used a lot in our TS codebase at work.

@imcotton
Copy link
Contributor

imcotton commented Feb 4, 2023

In retrospect there are voidRight and voidLeft pairs in alike also missing in fp-ts:

(<$) :: f a b. Functor f => a -> f b -> f a
($>) :: f a b. Functor f => f a -> b -> f b

Maybe having similar (flapFlipped or flapV) without breaking change of existing flap to compensate the lack of infix operator?

Indeed a reliable flip helps a lot in practices, finding myself also using utils like elemV for missing pieces thanks to fp-ts-std btw.

@samhh
Copy link
Contributor Author

samhh commented Feb 4, 2023

I'd love a flapV! I went with "V" as it sort of looks like a mirror, but any naming convention would suffice.

Very much agreed on $> and <$ also. I twitch every time I write map(constant(x)) 😄

@joshdifabio
Copy link

I'm having exactly the same issue as @samhh. The current param order is yet to work for me.

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