["Request"] Declarative (sub-)type checks yielding Option<*> #3572
Replies: 4 comments
-
|
How about
|
Beta Was this translation helpful? Give feedback.
-
|
Good and helpful ideas, but if you have many type checks you might still end up with lots of boilerplate. Reducing boilerplate was probably also the intention of Arrow's The first proposal might throw a |
Beta Was this translation helpful? Give feedback.
-
|
I'm not sure that this belongs to Arrow, to be honest. I don't think the pattern of moving to |
Beta Was this translation helpful? Give feedback.
-
|
To add to the previous comments, This style of function is explicitly recommended against, since it doesn't give you compile-time warnings for e.g. erased generics |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Arrow provides this handy
public fun <T> T?.toOption(): Option<T> = this?.let { Some(it) } ?: Noneextension function which converts nullable types toOptiondtos.There are some use cases I have where having this functionality for subtype checks is pretty handy replacing imperative is-checks.
I guess it's clear what I'm trying to say. The above is just an illustration to depict my thoughts.
Beta Was this translation helpful? Give feedback.
All reactions