However, this restricts us to having both first and second collections of the same type. Shouldn't different types (e.g. a list and a set) be allowed? And how to implement this?
Before reading the solution I tried this signature:
but it gives a type mismatch error: inferred type kotlin.List<kotlin.String> is not a subtype of kotlin.MutableCollection<kotlin.String> (when this function is used like partitionTo(ArrayList<String>(), ArrayList()) { s -> !s.contains(" ") }).
The proposed correct solution states that the
partitionTo
function signature should look like this:However, this restricts us to having both
first
andsecond
collections of the same type. Shouldn't different types (e.g. a list and a set) be allowed? And how to implement this?Before reading the solution I tried this signature:
but it gives a type mismatch error:
inferred type kotlin.List<kotlin.String> is not a subtype of kotlin.MutableCollection<kotlin.String>
(when this function is used likepartitionTo(ArrayList<String>(), ArrayList()) { s -> !s.contains(" ") }
).