Skip to content

How to eliminate ternary operators or if-else with fp-ts #1835

Answered by elamurugan-r
elamurugan-r asked this question in Q&A
Discussion options

You must be logged in to vote

Hey Everyone,
I tried the below and it worked:

pipe(
    paramM,
    O.chain((param) => param.arr),
    O.chain(parr => 
	pipe(
	    isComp,
            O.fromPredicate(x => x),
            O.chain(() => RA.findFirst((x: string) => x === "react")(parr)),
            O.alt(() => RA.head(parr))
       )
   ),
   O.getOrElse(() => "javascript")
)

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by elamurugan-r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants