navigation

AvoidSinglePipeOperator (FL0077)

Introduced in 0.21.5

Cause

Use of the pipe operator when only one invocation is employed.

Rationale

When the use of the pipe operator happens for a single invocation (instead of a multiple one, which would add a chain of them, usually staggered across many lines), it doesn't aid readibility.

This rule does not apply to functions with more than one argument. The reason for that is primarily application of higher-order functions such as map or iter, for which type inference may break without using pipe operator. And it also it helps to have the collection, which is iterated over, to be on top.

This rule also does not apply when an argument passed to pipe operator spans multiple lines.

Example of single pipe operator usage:

let someFunc someParam =
    someParam
    |> someOtherFunc

Example of multiple pipe operator usage:

let someFunc someParam =
    someParam
    |> someOtherFunc
    |> yetAnotherFunc

Example of single pipe applied to function with several arguments:

projectsInOrder 
    |> Seq.map(fun proj -> proj.AbsolutePath |> FileInfo)

Example of single pipe applied to an argument that spans multiple lines:

[
    "John"
    "Doe"
]
|> List.length

How To Fix

Just use a normal function call, without the need for any operator:

let someFunc someParam =
    someOtherFunc someParam

Rule Settings

{
    "avoidSinglePipeOperator": { "enabled": false }
}