Cartesian product version of List andMap
and mapN
functions.
This module's functions behave differently from the "common" ones in
elm/core
and
elm-community/list-extra
in that instead of zipping they will run through all combinations of the lists
you provide:
List.Cartesian.map2 (+) [ 1, 2 ] [ 100, 200, 300 ]
--> [ 101, 201, 301, 102, 202, 302 ]
Compare that with the default zipping behaviour:
List.map2 (+) [ 1, 2 ] [ 100, 200, 300 ]
--> [ 101, 202 ]
andMap : List a -> List (a -> b) -> List b
A building block for arbitrary mapN
functions. See map5
for more
info.
Note that andMap
allows you to do stuff you might not realize is
possible with map2
etc.:
[ (+), (*) ]
|> List.Cartesian.andMap [ 1, 2 ]
|> List.Cartesian.andMap [ 90, 93, 96 ]
--> [ 91, 94, 97, 92, 95, 98, 90, 93, 96, 180, 186, 192 ]
map2 : (a -> b -> c) -> List a -> List b -> List c
Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
Also equivalent to List.Extra.lift2
.
List.Cartesian.map2 (*) [ 10, 100 ] [ 1, 2, 3 ]
--> [ 10, 20, 30, 100, 200, 300 ]
map3 : (a -> b -> c -> d) -> List a -> List b -> List c -> List d
Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
|> List.Cartesian.andMap zs
Also equivalent to List.Extra.lift3
.
map4 : (a -> b -> c -> d -> e) -> List a -> List b -> List c -> List d -> List e
Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
|> List.Cartesian.andMap zs
|> List.Cartesian.andMap ws
Also equivalent to List.Extra.lift4
.
map5 : (a -> b -> c -> d -> e -> f) -> List a -> List b -> List c -> List d -> List e -> List f
Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
|> List.Cartesian.andMap zs
|> List.Cartesian.andMap ws
|> List.Cartesian.andMap vs
In case you're looking for map6
etc., you can use the above andMap
pattern to map as many lists you want.