In my style of writing WL, I typically use pure functions inline, without assigning them to a name, as when writing the function argument to Map
. For functions that I want to be part of my package, I use function definitions (the SetDelayed
option).
Function definitions are generally my go-to default, because they have many advantages:
* pattern-matching, which you mentioned; this doubles as a sort of documentation for the function, similar to the way types can hint at how to use a function
* attributes (Protected
, HoldAll
) can be assigned to a symbol; there is a way to assign attributes to pure functions but I find the syntax awkward and can't recall ever having done it
* because of the function definitions use pattern-matching, it lends itself to writing overloads of a function, which I use a lot
Pure functions, when used anonymously (without assigning them to a simple), are good when a relatively simple transformation needs to be done, as with Map
, Fold
, or SortBy
(or any of the other *By functions). Although even with Map
and Fold
I sometimes find the function gets bigger than I first expected, and I move it to be a function definition assigned to a named symbol.