FunLand.Builtin.Map (fun_land v0.10.0)
Maps are Mappable, because we can map over {k, v}
-tuples to create new values.
(
Note that different from the Map
implementation of Enum.map
, the result should be a new value, and not a new {key, value}-tuple.
There is no way to alter the key while mapping over a Map, as the key is part of the structure, rather than its contents!
)
Maps are however not Appliable, (TODO: Explanation)
Maps are not Applicative, as there is no way to put 'a value' inside a map (we don't know what key to associate it with)
so we cannot define an implementation of new/1
.
Maps are SemiCombinable, as we can take two key-value groups, and combine them (with duplicates being overridden by the values in the latter).
Maps are also Combinable, as it is also possible to create a empty
element: an empty map.
Link to this section Summary
Functions
Callback implementation for FunLand.Combinable.empty/0
.
A variant of reduce that accepts anything that is Combinable as second argument. This Combinable will determine what the empty value and the combining operation will be.
Callback implementation for FunLand.Reducible.reduce/3
.
Converts the reducible into a list, by building up a list from all elements, and in the end reversing it.
Link to this section Functions
combine(map_a, map_b)
empty()
Callback implementation for FunLand.Combinable.empty/0
.
map(map, function)
reduce(a, combinable)
A variant of reduce that accepts anything that is Combinable as second argument. This Combinable will determine what the empty value and the combining operation will be.
Pass in the combinable module name to start with empty
as accumulator,
or the combinable as struct to use that as starting accumulator.
This is an automatic function implementation, made possible because FunLand.Builtin.Map
implements the FunLand.Reducible
behaviour.
See FunLand.Reducible.reduce/2
for examples.
reduce(map, initial, folding_function)
Callback implementation for FunLand.Reducible.reduce/3
.
to_list(reducible)
Converts the reducible into a list, by building up a list from all elements, and in the end reversing it.
This is an automatic function implementation, made possible because FunLand.Builtin.Map
implements the FunLand.Reducible
behaviour.