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

implement ifElse #32

Open
kutyel opened this issue May 22, 2020 · 1 comment
Open

implement ifElse #32

kutyel opened this issue May 22, 2020 · 1 comment

Comments

@kutyel
Copy link
Contributor

kutyel commented May 22, 2020

Hi! now that I'm back to typescript, I'm willing to learn fp-ts but I miss some functions from ramda too much 馃槶, how would ifElse be implemented? Thanks!

@giogonzo
Copy link
Owner

If I guess the ifElse signature correctly from the ramda docs, it should be something like (+ currying, ignored here):

function ifElse<A, R>(predicate: (a: A) => boolean, whenTrue: (a: A) => R, whenFalse: (a: A) => R, a: A): R

I believe it could also provide an overload similar to:

function ifElse<A, B, R>(predicate: (a: A) => a is B, whenTrue: (a: B) => R, whenFalse: (a: A) => R, a: A): R

@kutyel would you like to send a PR? I can provide more help if needed!

Manual currying should be implemented similar to any other function implemented in this repo.

For the actual logic of the function, I would go with something like (beware, not even tested in the editor!):

import { fold } from 'fp-ts/lib/boolean'

pipe(
  a,
  predicate,
  fold(() => whenFalse(a), () => whenTrue(a))
)

@kutyel kutyel mentioned this issue May 27, 2020
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

Successfully merging a pull request may close this issue.

2 participants