Why does the pipe operator work?

前端 未结 4 1102
一个人的身影
一个人的身影 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:16

    As others have said above, basically you're misunderstanding what result2 would resolve to. It would actually resolve to

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

    List.map takes two arguments: a function to apply to all elements in a list and a list. (fun x -> x * x * x) is the first argument and [2;4;6] is the second.

    Basically just put what's on the left of |> after the end of what's on the right.

提交回复
热议问题