Home > Software engineering >  Is there something similar to list comprehensions in Elm?
Is there something similar to list comprehensions in Elm?

Time:01-16

If I understood it correctly Elm doesn't have something like list comprehension.

What would you use instead if you for example would like to map the numbers 1 to 100 to something else?

CodePudding user response:

I think List.range and pipeline style read very well togeher. But it is not as succinct as a list comprehension in python.

module Main exposing (main)

import Html


main =
    List.range 1 10
        |> List.map square
        |> List.map String.fromInt
        |> String.join ", "
        |> Html.text


square : Int -> Int
square a =
    a ^ 2
  •  Tags:  
  • elm
  • Related