Since functions in FSharp with multiple parameters get curried inherently into functions with only one parameter, should the signature of Seq.filter
have to be
Seq.filter predicate source
? How different will it be from
Seq.filter source predicate
Thanks
The first order (predicate, sequence) is more appropriate for chaining sequence combinators via the |>
operator. Typically, you have a single sequence to which you apply a number of operations/transformations, consider something like
xs |> Seq.map ... |> Seq.filter ... |> Seq. ...
etc. Reversing the order of the parameters to (source, predicate) would prohibit that (or at least make it much more awkward to express). That (and maybe also partial application) is why for (almost) all the default Seq
combinators the last parameter is the sequence the operation is applied to.
The reason it is
Seq.filter predicate source
instead of
Seq.filter soure predicate
is so that you can do this
source
|> Seq.filter predicate
Since you are more likely to build a new function using Seq.filter predicate
let isEven = Seq.filter (fun x -> x % 2 = 0)
you can now do
source |> isEven
There are functions in F# where the order of parameters are not done like this because of it's history of coming from OCaml. See: Different argument order for getting N-th element of Array, List or Seq
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With