Leandro Borges Ferreira
10/25/2018, 2:34 PMHaskell: fmap :: (a -> b) -> f a -> f b
Kotlin (simplified): TA.map() -> TB ; T extends Iterable
The best we can do is:
Haskell: fmap :: (a -> b) -> List a -> List b
Kotlin (simplified): IterableA.map() -> ListB
So we have some odd behaviours like this one:
val list = LinkedList<String>().map { } //This is a List and the implementation is ArrayList o.O. I would like to keep LinkedList
//This is true for any other implementation of List
val a : Map<String, String> = TreeMap()
a.k()
a.map { } //Now I have LinkedHashMap inside the MapK =|
The solution:
Since we have Higher Order Types in Arrow, it would be possible to change the implementation of map
to:
fun <F: ForIterable, A, B> Kind<F, A>.map() -> Kind<F, B>
Since we have a parametrised type as the container, it wouldn't change the implementation of the collection. So a map of a LinkedList would return a LinkedList, not an ArrayList.