How to use |> operator with a function which expects two parameters?

96 Views Asked by At
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
1

There are 1 best solutions below

0
On BEST ANSWER

|> 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