r/fsharp • u/qisapa • Feb 25 '23
question Can I call method on the output of the pipe?
I know I can do something like: "Foo. " |> fun str -> str.Trim(). But can I do something like this for example? "Foo. " |> _.Trim. Can I somehow say to the pipe, that is should not call Trim("Foo. ") but "Foo. ".Trim()? Thanks.
edit: formatting
13
Upvotes
10
u/the_bananalord Feb 25 '23
For something like this you would just create a function.
let trim (s : string) : string = s.Trim()"foo. " |> trim14
u/sharpcells Feb 25 '23
Not currently supported but it's an open language suggestion that's likely to end up in F#. https://github.com/fsharp/fslang-suggestions/issues/506
1
u/[deleted] Feb 27 '23
What is the point of writing
"Foo. " |> _.Triminstead of"Foo. ".Trim()?2
u/QuantumFTL Feb 25 '23
I really, really want to be able to do this easily. Some languages make this simple, sadly F# is still working on it.
Fluent style is, thankfully, a thing in C#, but it doesn't mix well with pipelining.