1

Cutting sequence into batches of fixed length, making overlapping sliding data windows, getting each n-th item from a sequence - all these tasks can be solved using a single generic slicing function. For example, Clojure offers for such purposes partition size skiplibrary function.

F# core library offers Seq.windowed function that implements sliding windows overlapping by 1. Seq.windowed width would be simply equivalent to partition width 1; varying partition arguments allows solving other problems: partition size size slices sequence into non-overlapping batches, partition 1 n gets each n-th sequence item, etc.

It is not that hard to implement such functionality in F#. I once posted a naive prototype that suffers from redundant sequence evaluations; however making it into truly lazy production quality F# implementation is definitely doable.

I wonder if it was any particular reason for limiting out-of-the-box F# core library offering for sequence slicing to Seq.windowed function only?

Community
  • 1
  • 1
Gene Belitski
  • 10,270
  • 1
  • 34
  • 54

1 Answers1

3

I don't think there is any good answer to your question.

There are certainly no technical difficulties that would make it impossible to implement a more general sliding window function. It can be implemented and it would be useful. Why is it not included in the F# core library? Probably because the F# team didn't try to include every possible useful function as it would make the core library too big, too difficult to maintain and harder to use (finding the right function would be difficult if there were too many of them).

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553