New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow piping into methods #1118
Comments
There's a bit of relevant discussion here that may be worth looking at: #506 (comment) It's an enormous thread so I don't expect anyone to read years of commentary. In theory I would like to have this supported. But I can't seem to land on a syntax I'd like. |
Value for now I think 🙂 |
@cartermp Do you think that qualifying the method with the class name (and without parentheses) would be better?
|
If I'm calling a method, then I shouldn't have to know what class name it belongs to - this kinda defeats the purpose of methods. |
Not to mention inheritance can somewhat complicate things. |
That thread Phillip linked is indeed huge. This looks ok for this sample: let configureApp (appBuilder : WebApplication) =
appBuilder
|> _.UseServerTiming()
|> configureStaticContent
|> _.UseHttpsRedirection()
|> addRoutes
|> _.UseRouting()
|> LibService.Kubernetes.configureApp LibService.Config.apiServerKubernetesPort
|> addRoutes
|> ignore<IApplicationBuilder> |
I'm suprised it doesn't include the |
Yes you're right it should, I've edited |
I think the One thing that I'll add is that this would imply some interesting tooling work so that meaningful completion lists can be generated. Related to the general issue of "meaningful completion within pipelines" wherein it would be good to read the type from the LHS of the pipeline operator and use that to inform what the completion list on the RHS does. |
This is what we do in @darklang in this situation, and it's quite effective. |
I'll close as a duplicate of #506 - this is an informative discussion which can inform some choices there |
I propose we allow piping into method calls. For example this code:
would become:
.NET code often is designed with for a "fluent" approach that allows for easy method chaining of C# code. It is more idiomatic in F# to use the pipe operator and pipelines instead of method chaining. However, using pipelines is awkward when it runs into common C#/.NET-designed interfaces.
The code above is adapted from configuring an Aspnetcore application on .Net 6, but I have felt this pain in lots of places, and have many pipelines that contain
fun x -> x.method()
.Another class of places I have felt this pain is:
where I need to wrap an F# function call expression in parentheses in order to call a method on it. This would be much nicer as:
This is particularly frustrating as I need to move my cursor to the start of the expression to add the opening
(
, while I could simply type|>
otherwise.This proposal is based on Elm, which has a delightful record access syntax:
Pros and Cons
The advantages of making this adjustment to F# are less verbose code, and better integration of fluent-style APIs into F#.
The disadvantages of making this adjustment to F# are a new syntactic tool, which would initially look a little weird to newcomers.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S? Feels like it could mostly happen in the early stages of compilation. But I really don't know.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: