I am trying to reimplement the List.distinct
function:
let inline distinct list =
let folder curr = function
| [] -> [curr]
| l -> if List.contains curr l then l else curr :: l
List.foldBack folder list []
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I got a lint warning that says
List.foldBack f x []
might be able to be refactored intox
However that doesn't make much sense to me as this leads me to return the original list without performing the distinct logic.
Is this a bug of FSharpLint?
Apparently that's a wrong rule. Take a look at this excerpt from FSharpLint's default configuration:
List.fold f x [] ===> x
Array.fold f x [||] ===> x
List.foldBack f x [] ===> x
Array.foldBack f x [||] ===> x
It's the same for fold
and foldback
here, so it doesn't follow the differences in signatures between the two.
The order of initial state and collection arguments should be flipped, see the "mnemonic" approach used in foldback
definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With