Different argument order for getting N-th element of Array, List or Seq

后端 未结 3 531
野趣味
野趣味 2020-12-16 00:43

Is there a good reason for a different argument order in functions getting N-th element of Array, List or Seq:

Array.get source index
List .nth source index
         


        
3条回答
  •  孤街浪徒
    2020-12-16 01:11

    Just use backward pipe operator:

    [1..1000] |> List.nth <| 42
    

    Since both operators are left associative, x |> f <| y is parsed as (x |> f) <| y, and this does the trick.

    Backward pipe operator is also useful if you want to remove parentheses: f (very long expression) can be replaced with f <| very long expression.

提交回复
热议问题