Rather trivial question, but a quick google search didn't give me the answer.
What is a standard way to write a recursive functions for sequences? For lists you would do pattern matching with empty list and head+tail pattern, what is the equivalent for sequences?
There is no standard way to do so since you rarely write recursive functions for sequences.
You should look at a variety of high-order functions in Seq module. They are often more than adequate, so you don't have to write recursive functions by yourself.
To generate sequences recursively, sequence expression is a simple and intuitive way to go:
let rec allFiles dir =
seq { yield! Directory.GetFiles dir
for d in Directory.GetDirectories dir do
yield! allFiles d }
If you have to break down a sequence and manipulate it recursively, you are doing it wrong. You should either manipulate List
or LazyList from F# PowerPack, and convert results back to sequences.
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