Groups and clumps

Factor handbook » The language » Collections » Sequence operations

Factor handbook » The language » Collections » Sequence operations

Prev: | Splitting sequences |

Next: | Destructive sequence operations |

Splitting a sequence into disjoint, fixed-length subsequences:

A virtual sequence for splitting a sequence into disjoint, fixed-length subsequences:

Splitting a sequence into overlapping, fixed-length subsequences:

Splitting a sequence into overlapping, fixed-length subsequences, wrapping around the end of the sequence:

A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:

A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences, wrapping around the end of the sequence:

The difference can be summarized as the following:

A combinator built using clumps:

Testing how elements are related:

group ( seq n -- array )

A virtual sequence for splitting a sequence into disjoint, fixed-length subsequences:

groups

<groups> ( seq n -- groups )

Splitting a sequence into overlapping, fixed-length subsequences:

clump ( seq n -- array )

Splitting a sequence into overlapping, fixed-length subsequences, wrapping around the end of the sequence:

circular-clump ( seq n -- array )

A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:

clumps

<clumps> ( seq n -- clumps )

A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences, wrapping around the end of the sequence:

circular-clumps

<circular-clumps> ( seq n -- clumps )

The difference can be summarized as the following:

• | With groups, the subsequences form the original sequence when concatenated: USING: grouping prettyprint ;
{ 1 2 3 4 } 2 group . { { 1 2 } { 3 4 } } USING: grouping prettyprint sequences ;
{ 1 2 3 4 } dup
2 <groups> concat sequence= . t |

• | With clumps, collecting the first element of each subsequence but the last one, together with the last subsequence, yields the original sequence: USING: grouping prettyprint ;
{ 1 2 3 4 } 2 clump . { { 1 2 } { 2 3 } { 3 4 } } USING: grouping assocs sequences prettyprint ;
{ 1 2 3 4 } dup
2 <clumps> unclip-last [ keys ] dip append sequence= . t |

• | With circular clumps, collecting the first element of each subsequence yields the original sequence. Collecting the nth element of each subsequence would rotate the original sequence n elements rightward: USING: grouping prettyprint ;
{ 1 2 3 4 } 2 circular-clump . { { 1 2 } { 2 3 } { 3 4 } { 4 1 } } USING: grouping assocs sequences prettyprint ;
{ 1 2 3 4 } dup
2 <circular-clumps> keys sequence= . t USING: grouping prettyprint ;
{ 1 2 3 4 }
2 <circular-clumps> [ second ] { } map-as . { 2 3 4 1 } |

A combinator built using clumps:

monotonic? ( seq quot: ( elt1 elt2 -- ? ) -- ? )

Testing how elements are related:

all-eq? ( seq -- ? )

all-equal? ( seq -- ? )

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.100 x86.64 (2240, heads/master-adff5af2b7, Sep 20 2023 21:16:03)