Prev: | Splitting sequences |
Next: | Destructive sequence operations |
• | 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 } |