FSharp.Core.Fluent icon indicating copy to clipboard operation
FSharp.Core.Fluent copied to clipboard

Consider adding a global .pipe method to simulate |>

Open OlegAlexander opened this issue 3 years ago • 1 comments

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.

OlegAlexander avatar Sep 25 '22 00:09 OlegAlexander

Could you submit a PR for this?

dsyme avatar Sep 25 '22 09:09 dsyme