FSharp.Core.Fluent
FSharp.Core.Fluent copied to clipboard
Consider adding a global .pipe method to simulate |>
Description
Please consider adding a completely generic .pipe method to simulate |>. For example:
open FSharp.Core.Fluent
open System.Runtime.CompilerServices
[<Extension>]
type FluentExtensions =
[<Extension>]
static member inline pipe(x, [<InlineIfLambda>]f) = f x
(4.0).pipe(sqrt) |> ignore // 2.0
"abc".pipe(String.length) |> ignore // 3
let magnitude (vec:list<float>) = vec.sumBy(fun x -> x * x).pipe(sqrt)
Thank you to Michael Oyer (@ michael) on the F# beginners Slack for the solution above.
This .pipe method would allow the user to stay consistent with the method chaining style rather than switching back and forth from . methods to |> for custom functions.
Could you submit a PR for this?