2 Comments

Of course in F# you would be wise to simply using the existing collections' functions already implemented by the compiler, so, depending on your data structure either `List.map (fun x -> x + 1) myLst` or `Array.map (fun x -> x + 1) myArr`, or, if all else fails, `Seq.map (fun x -> x +1) mySeq`.

Also note that as of .Net 8 the entire `(fun x -> x + 1)` can be written shorter: `Seq.map (_ + 1) mySeq`, but personally I like the verbose syntax better for clarity (or, if you're prior to .Net 8, that's pretty much required).

List/Array destructuring is used in F# only for very specific use-cases, where the usual collection functions are not **just** right.

For a simple "increment every element by 1"... just use `map`.

(BTW, most modern programming languages, which is to say NOT Go, have this functionality).

Expand full comment

True, readers that already know functional programming are encouraged to use `List.map` instead of relying on a recursive function that does something equivalent.

Expand full comment