gcanti / fp-ts

Functional programming in TypeScript
https://gcanti.github.io/fp-ts/
MIT License
10.89k stars 503 forks source link

Add select-ts to ecosystem #1191

Open mstn opened 4 years ago

mstn commented 4 years ago

📖 Documentation

I am building a package select-ts for fp-ts for behaviors of type "if this condition is true, then do that". It is based on:

I think it could be useful for implementing Ramda-like conditionals even if probably goals are different from those in fp-ts-ramda.

It is still very experimental. What do you think? Does it make sense to you?

giogonzo commented 4 years ago

FWIW, I had myself a try at "fp-ts and Selective" some time ago

it could be useful for implementing Ramda-like conditionals even if probably goals are different from those in fp-ts-ramda.

I didn't look at the code in select-ts yet, but if it is indeed an encoding of selective functors for fp-ts, it might be good to reimplement some related ramda functions in fp-ts-ramda based on it

mstn commented 4 years ago

Hey @giogonzo I haven't seen your pr!

Yes, it is an encoding for selective functors in fp-ts. As in the original paper, you can build one from a Monad (getSelectM) or from an Applicative (missing). The execution semantics is different in the two cases.

For example, when is very Ramda-ish. You can find other Ramda-like operators in the project: cond, unless, ifElse...

Imo also retry-ts can be rewritten using a selective functor. I have already implemented a while operator, it shouldn't be much different.