In F# we have List.partition
and Array.partition
which return a tuple of lists and a tuple of arrays respectively.
so, why is there no Seq.partition
returning a tuple of sequences?
here is a very simple implementation: F# Snippets
so... why isn't this part of the core?
If it is, please let us know via a Comment In 12.1 DBMS_METADATA.GET_DDL ('SEQUENCE',....) return the undocumented clause PARTITION/NOPARTITION. The column PARTITION_COUNT exists in all *_SEQUENCE views, and in the underlying table seq$ (PARTCOUNT).
The output is as follows. Seq.pairwise creates a new sequence in which successive elements of the input sequence are grouped into tuples. Seq.windowed is like Seq.pairwise, except that instead of producing a sequence of tuples, it produces a sequence of arrays that contain copies of adjacent elements (a window) from the sequence.
The Seq module in the Microsoft.FSharp.Collections namespace contains functions for working with sequences. These functions work with lists, arrays, maps, and sets as well, because all of those types are enumerable, and therefore can be treated as sequences.
The Seq module provides support for manipulations involving sequences. A sequence expression is an expression that evaluates to a sequence. Sequence expressions can take a number of forms. The simplest form specifies a range. For example, seq { 1 .. 5 } creates a sequence that contains five elements, including the endpoints 1 and 5.
In F# 4.0 (Visual Studio 2015), the core libraries are a lot more uniform than before, but they still do not come with an implementation of Seq.partition
. You can find more about this in the F# language design discussion: Regular functional operators producing two or more output collections.
The summary is that the Seq.partition
function is quite tricky and a having it could introduce potential performance issues. There a couple of ways it can work:
It can iterate over the input collection twice (like the FsSnip version), which can cause issues if you have complex delayed computation (you're doing everything twice)
It can iterate over the input once, but then it would have to do some complex mutable state sharing (which could secretly allocate memory).
So, Seq.partition
cannot be implemented reasonably while keeping all the good properties that you would expect about the seq<'T>
type.
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