Skip to content

Instantly share code, notes, and snippets.

@fredcy
Last active November 2, 2019 18:03
Show Gist options
  • Save fredcy/5746b0af5ddb3f23f27470f41c883f86 to your computer and use it in GitHub Desktop.
Save fredcy/5746b0af5ddb3f23f27470f41c883f86 to your computer and use it in GitHub Desktop.
Cartesian product of two lists in Elm
import Html exposing (text)
main =
text <| toString <| cartesian ["a", "b", "c"] [1..5]
cartesian : List a -> List b -> List (a,b)
cartesian xs ys =
List.concatMap
( \x -> List.map ( \y -> (x, y) ) ys )
xs
cartesianExtra xs ys =
List.Extra.lift2 (,) xs ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment