Idiomatic way to use Option
and flow
#1453
Replies: 3 comments 6 replies
-
I'm a bit confused by your example, since Anyway, TypeScript's infer is failing in this case, so you have to help it by annotating the signature of const myFunc: (o: O.Option<number>) => number = flow(
O.map((n) => n + 1),
O.map((n) => n * 2),
O.getOrElse(() => 0),
) I hope this answers your question. |
Beta Was this translation helpful? Give feedback.
-
Something I'd like to add, somewhat orthogonal to the question asked, is that in my view it's generally bad practice to define functions that take monads as their "data" input. You can't do anything with a Your function is currently On the other hand, if you change the signature to |
Beta Was this translation helpful? Give feedback.
-
I'm sorry for the confusion, there's a mistake in my example. I tweaked As I'm inexperienced with FP and Here is how I'm trying to set up a selector:
|
Beta Was this translation helpful? Give feedback.
-
Say I have defined a
Option
al type without an explicit name for the contained type:And say I want to define a
flow
that takesMyOption
and does something with it:I can solve this easily by defining a utility type
GetOptionType
:Is this the idiomatic way to do things? Thank you in advance for your help!
EDIT: Corrected a mistake in my example code.
Beta Was this translation helpful? Give feedback.
All reactions