https://kotlinlang.org logo
#announcements
Title
# announcements
e

Eric O'Connell

07/12/2019, 7:57 PM
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

streetsofboston

07/12/2019, 7:59 PM
Introduce a generic super type.
e.g.
fun <T, S, D : S, R : S> Optional<T>.mapDefault(default: D, mapper: (T) -> R): S
e

Eric O'Connell

07/12/2019, 8:06 PM
wow, niiiice
Thank you!