问题
I remember reading about the double pipe operators -- ||> and <|| -- somewhere and now I can't remember where. I can't find them on MSDN or in the language spec. Are they documented anywhere?
Example
let print a b = sprintf "%O %O" a b
(1, 2) ||> print
// val it : string = "1 2"
回答1:
Double (forward/backward) pipe operators are documented in the list of F# operators on MSDN and are also documented as a function exported from the Core.Operators module.
This is probably automatically generated from the XML documentation in the F# sources, so the pages have somewhat cryptic names:
- Operators.( ||> )<'T1,'T2,'U> Function (F#)
- Operators.( <|| )<'T1,'T2,'U> Function (F#)
As a side-note, finding the operator using search engines is a bit of a problem, so I looked in the F# sources (distributed with CTP release) and the prim-types.fs
includes the following:
/// <summary>Apply a function to two values, the
/// values being a pair on the left, the function on the right</summary>
/// <param name="arg1">The first argument.</param>
/// <param name="arg2">The second argument.</param>
/// <param name="func">The function.</param>
/// <returns>The function result.</returns>
val inline (||>): arg1:'T1 * arg2:'T2 -> func:('T1 -> 'T2 -> 'U) -> 'U
I was going to recommend the F# sources as a good documentation for this kind of thing (which they certainly are), but then I pasted a part of the <summary>
tag to google and found the pages mentioned above :-).
回答2:
See @Tomas' answer. The key aspect is that these are merely functions in the library, so you want to look in the library docs (and Core.Operators contains these guys).
来源:https://stackoverflow.com/questions/2867625/are-the-double-forward-backward-pipe-operators-documented