Skip to content

Commit 9022b0d

Browse files
CopilotBillWagner
andauthored
Add formatting guidelines for F# reverse pipeline operator (#48742)
* Initial plan * Add guidance for reverse pipeline operator formatting Co-authored-by: BillWagner <[email protected]> * Update docs/fsharp/style-guide/formatting.md * Update reverse pipeline examples to align with Fantomas formatting conventions Co-authored-by: BillWagner <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: Bill Wagner <[email protected]>
1 parent dc9f9f3 commit 9022b0d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/fsharp/style-guide/formatting.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,30 @@ let methods2 = System.AppDomain.CurrentDomain.GetAssemblies()
395395
|> Array.concat
396396
```
397397

398+
For reverse pipeline `<|` operators, keep short expressions on a single line. When line length requires wrapping, place arguments on new lines and align them consistently:
399+
400+
```fsharp
401+
// ✔️ OK - short expressions stay on one line
402+
let result = someFunction <| arg1 <| arg2 <| arg3
403+
404+
// ✔️ OK - longer expressions can wrap when necessary
405+
failwith
406+
<| sprintf "A very long error message that exceeds reasonable line length: %s - additional details: %s"
407+
longVariableName
408+
anotherLongVariableName
409+
410+
// ✔️ OK - align continuation lines with the operator
411+
let longResult =
412+
someVeryLongFunctionName
413+
<| firstVeryLongArgumentName
414+
<| secondVeryLongArgumentName
415+
<| thirdVeryLongArgumentName
416+
417+
// ❌ Not OK - unnecessary wrapping of short expressions
418+
failwith <| sprintf "short: %s"
419+
value
420+
```
421+
398422
### Formatting lambda expressions
399423

400424
When a lambda expression is used as an argument in a multi-line expression, and is followed by other arguments,
@@ -571,6 +595,7 @@ The following operators are defined in the F# standard library and should be use
571595
```fsharp
572596
// ✔️ OK
573597
x |> f // Forward pipeline
598+
f <| x // Reverse pipeline
574599
f >> g // Forward composition
575600
x |> ignore // Discard away a value
576601
x + y // Overloaded addition (including string concatenation)

0 commit comments

Comments
 (0)