Zipping version of List andMap
and mapN
functions.
This module exists mainly to illustrate the difference between the
List.Cartesian
functions and the "common" ones from elm/core
and elm-community/list-extra
.
The mapN
functions in this module are aliases of the functions found in
List
:
List.Zip.map2
= List.map2
and so on.
andMap : List a -> List (a -> b) -> List b
Same as List.Extra.andMap
.
A building block for arbitrary mapN
functions, but beware: there is a gotcha.
See map5
for more info.
Note that the zipping behaviour will drop items if your lists aren't of the same length.
map2 : (a -> b -> c) -> List a -> List b -> List c
Same as List.map2
.
Note that the zipping behaviour will drop items if your lists aren't of the same length.
List.Zip.map2 (*) [ 10, 100 ] [ 1, 2, 3 ]
--> [ 10, 200 ]
map3 : (a -> b -> c -> d) -> List a -> List b -> List c -> List d
Same as List.map3
.
Note that the zipping behaviour will drop items if your lists aren't of the same length.
map4 : (a -> b -> c -> d -> e) -> List a -> List b -> List c -> List d -> List e
Same as List.map4
.
Note that the zipping behaviour will drop items if your lists aren't of the same length.
map5 : (a -> b -> c -> d -> e -> f) -> List a -> List b -> List c -> List d -> List e -> List f
Same as List.map5
.
Note that the zipping behaviour will drop items if your lists aren't of the same length.
In case you're looking for map6
etc., you can use this andMap
pattern to map
as many lists you want:
List.repeat listLength fn
|> List.Zip.andMap list1
|> List.Zip.andMap list2
|> List.Zip.andMap list3
|> List.Zip.andMap list4
|> List.Zip.andMap list5
|> List.Zip.andMap list6
|> ...
The gotcha is in that you need to provide the function repeated: [fn] |> ...
would not work correctly, as it would return a list with at most 1 item inside.