Why does the pipe operator work?

前端 未结 4 1108
一个人的身影
一个人的身影 2021-02-13 12:44

If the pipe operator is created like this:

let (|>) f g = g f

And used like this:

let result = [2;4;6] |> List.map (fun x         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 13:30

    The brackets around |> mean it is an infix operator so your example could be written

    let result = (|>) [2;4;6] (List.map (fun x -> x * x * x))
    

    Since |> applies its first argument to the second, this is equivalent to

    let result = (List.map (fun x -> x * x)) [2;4;6]
    

提交回复
热议问题