aeruhxi
08/13/2019, 7:21 AMfun <K, V, R> Map<out K, V>.map(
transform: (Entry<K, V>) -> R
): List<R>
Why does map
for Map
in stdlib return List
instead of Map
?Imran/Malic
08/13/2019, 7:25 AMmap
to map over every V
aeruhxi
08/13/2019, 7:30 AMraulraja
08/13/2019, 7:31 AMaeruhxi
08/13/2019, 7:35 AMImran/Malic
08/13/2019, 7:55 AMmap
doesn’t make senseImran/Malic
08/13/2019, 8:00 AMfmap (f . g) = fmap f . fmap g
Functor’s need to obey the order in order for this to work. It is implicit for sure.aeruhxi
08/13/2019, 8:26 AMsimon.vergauwen
08/13/2019, 8:27 AMList
. Everything that is an Iterable<A>
returns List
on map
.simon.vergauwen
08/13/2019, 8:27 AMaeruhxi
08/13/2019, 8:29 AMsimon.vergauwen
08/13/2019, 8:31 AMsetOf(1, 2).map { it + 1 }
calls fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R>
simon.vergauwen
08/13/2019, 8:32 AMIterable
you get map for free but it turns your structure into a `List`…tmg
08/13/2019, 10:10 AMtmg
08/13/2019, 10:10 AMtmg
08/13/2019, 10:12 AMWhich means that if you implementWhich means thatyou get map for free but it turns your structure into a `List`…Iterable
map
of Iterable is not the same map
of the functor
tmg
08/13/2019, 10:16 AMmap id = id
tmg
08/13/2019, 10:16 AMtmg
08/13/2019, 10:17 AMmap (f . g) = map f . map g
should still hold.tmg
08/13/2019, 10:20 AMMap
type then it shouldn't matter for its =
operation as well.tmg
08/13/2019, 10:21 AMMap
form a functor?tmg
08/13/2019, 10:24 AMMap
I would say that Map A and Map B are equal if for every (x, y) in A, it is also in B, and for every (x', y') in B, it is also in A.
It's specific of the general Set equality.tmg
08/13/2019, 10:25 AMmap
of Map
returning a List
is simply wrong.tmg
08/13/2019, 10:25 AMmap
for Map
tmg
08/13/2019, 10:29 AMYes, otherwiseThis statement is wrong.doesn’t make sensemap
map
respects order for list, because that is a property of a list, if 2 list do not have the same ordering, they are not the same list. But that is not true for Sets, ordering is not a property of the set, order does not matter for the set, so map
doesn't need to respect it.
map
just has to respect 2 laws:
map id = id
map (f . g ) = map f . map g
tmg
08/13/2019, 10:52 AMImran/Malic
08/13/2019, 11:21 AMtmg
08/13/2019, 11:35 AMit could not guarantee for example that mapping over the identity returns the same value if each time you iterate you get a different order.Why? Why would order of iteration would matter? Can you give an example on how applying
id
with different order would break the law?tmg
08/13/2019, 11:35 AMImran/Malic
08/13/2019, 11:42 AMFunctor's#map
is that it leaves the structure from F
unmodifiedImran/Malic
08/13/2019, 11:43 AMtmg
08/13/2019, 11:44 AMImran/Malic
08/13/2019, 11:45 AMtmg
08/13/2019, 11:45 AMtmg
08/13/2019, 11:46 AMtmg
08/13/2019, 11:46 AMtmg
08/13/2019, 11:46 AMtmg
08/13/2019, 11:46 AMsimon.vergauwen
08/13/2019, 11:47 AMFunctor
instances for `Map`…tmg
08/13/2019, 11:47 AMsimon.vergauwen
08/13/2019, 11:47 AMFunctorLaws
property based testing.simon.vergauwen
08/13/2019, 11:48 AMOrderedMap
has a separate instance that relies on Order
typeclass to guarantee order.simon.vergauwen
08/13/2019, 11:49 AMIterable
since the language doesn’t understand higher kind polymorphism. With KEEP-87 that could be rectified in the std.tmg
08/13/2019, 11:49 AMsimon.vergauwen
08/13/2019, 11:50 AMraulraja
08/14/2019, 9:37 PM