Exercise about generics from Kotlin Education presentation

It’s a generics exercise… So, of course, this is the solution:

fun <T, S : R, R> funny(
   source: Iterator<T>,
   target: MutableCollection<in R>,
   base: S,
   how: (R, T) -> R
)

The in R allows R to be narrowed down to C instead of being upcast to A. I really don’t see the point of having S though.

1 Like