Mark Pattison
Mark Pattison

Reputation: 3039

Is there an F# operator to express this function?

I've got the following code:

let funcsAppliedToData data = funcs |> Seq.map (fun f -> f data)

Is there an operator to express the function defined in the brackets (or a neater way of writing the whole line, for that matter)?

Upvotes: 2

Views: 66

Answers (1)

Tomas Petricek
Tomas Petricek

Reputation: 243126

You can rewrite this using a partial function application of the |> operator. The function you have:

 (fun f -> f data)

Can also be written using the pipe operator:

 (fun f -> data |> f)

You can treat the operator as a function:

 (fun f -> (|>) data f)

Now you could use partial function application:

 ((|>) data)

This answers your question, but I don't think I would use this in practice. Writing the function explicitly may be a couple of characters longer, but I just find it much more readable. The pipe operator is not usually used in the above way and so anyone reading the code will basically have to reverse the process I described here to understand what's going on.

Upvotes: 5

Related Questions