▲ | zelphirkalt 5 days ago | ||||||||||||||||||||||
I wouldn't say "rarely", unless you have a whole host of other higher order functions at your disposal for more special cases than map and fold. There are many cases, where you don't want to fold or map over the whole data structure and want to exit early with a result already. Writing tail recursive functions is still very common. | |||||||||||||||||||||||
▲ | munchler 5 days ago | parent [-] | ||||||||||||||||||||||
> I wouldn't say "rarely", unless you have a whole host of other higher order functions at your disposal for more special cases than map and fold That is my point. Modern functional languages do have a host of higher-order functions for exactly this sort of thing. For example, here is F#'s `Seq` module, for working with lazy sequences: https://fsharp.github.io/fsharp-core-docs/reference/fsharp-c... > There are many cases, where you don't want to fold or map over the whole data structure and want to exit early with a result already. Writing tail recursive functions is still very common. I think this can usually be handled more concisely by combining higher-order functions instead. For example, if you want to fold over a partial data structure, you can use `filter` to select only the elements you want, and then fold over that subset. Or, if you want to exit early from a map, you can use `takeWhile` and only map over what's left. Real-world functional programming is usually about combining these built-in tools effectively, rather than writing new tools from scratch. | |||||||||||||||||||||||
|