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 ]Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ysAlso equivalent to List.Extra.lift2.
List.Cartesian.map2 (*) [ 10, 100 ] [ 1, 2, 3 ]
--> [ 10, 20, 30, 100, 200, 300 ]Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
|> List.Cartesian.andMap zsAlso equivalent to List.Extra.lift3.
Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
|> List.Cartesian.andMap zs
|> List.Cartesian.andMap wsAlso equivalent to List.Extra.lift4.
Equivalent to
[ fn ]
|> List.Cartesian.andMap xs
|> List.Cartesian.andMap ys
|> List.Cartesian.andMap zs
|> List.Cartesian.andMap ws
|> List.Cartesian.andMap vsIn case you're looking for map6 etc., you can use the above andMap
pattern to map as many lists you want.
A building block for arbitrary
mapNfunctions. Seemap5for more info.Note that
andMapallows you to do stuff you might not realize is possible withmap2etc.: