If I have a function `fun <T, R> Optional&lt...
# announcements
e
If I have a function
fun <T, R> Optional<T>.mapDefault(default: R, mapper: (T) -> R): R
and call it with a default of a subtype of a
sealed class
e.g.
maybeThing.mapDefault(Action.NoFoo) { thing -> Action.Foo }
then this fails type checking because
R
in
mapDefault
is bound to
Action.NoFoo
— is there a good way around this besides calling
maybeThing.mapDefault<Thing, Action>
?
s
Introduce a generic super type.
e.g.
fun <T, S, D : S, R : S> Optional<T>.mapDefault(default: D, mapper: (T) -> R): S
e
wow, niiiice
Thank you!