0
kll : Float
kll =
    let
        half x =
            x / 2
    in
    List.sum (List.map half (List.map toFloat (List.range 1 10)))

converting using |>

can you also explain how to use the |> correctly with some examples cant find any online? Thanks This is my code:

kll : List Float
kll =
    let
        half x =
            x / 2
    in
    ((1 |> 1 |> List.range) |> toFloat |> List.map) (|>half |> List.map))|> List.sum
bdukes
  • 152,002
  • 23
  • 148
  • 175
y.west
  • 21
  • 4
  • 1
    Does this answer your question? [how to correctly use |> operator?](https://stackoverflow.com/questions/64480001/how-to-correctly-use-operator) – glennsl Oct 22 '20 at 12:51

1 Answers1

2

|> doesn't work with 2-parameter functions. It only feeds into functions that take one parameter.

Use currying to supply leading parameters. I think what you want is this:

List.range 1 10 |> List.map toFloat |> List.map half |> List.sum

Or more simply:

List.range 1 10 |> List.map (\x -> toFloat x / 2) |> List.sum
Nick Lee
  • 5,639
  • 3
  • 27
  • 35