Christian
Christian

Reputation: 7852

Is there something similar to list comprehensions in Elm?

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?

Upvotes: 1

Views: 105

Answers (1)

marcw
marcw

Reputation: 873

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

Upvotes: 2

Related Questions