change clump when the group size is greater than the sequence length
							parent
							
								
									40ca3fc7f3
								
							
						
					
					
						commit
						2fc1442771
					
				| 
						 | 
				
			
			@ -117,7 +117,7 @@ $nl
 | 
			
		|||
HELP: clump
 | 
			
		||||
{ $values { "seq" "a sequence" } { "n" "a non-negative integer" } { "array" "a sequence of sequences" } }
 | 
			
		||||
{ $description "Splits the sequence into overlapping clumps of " { $snippet "n" } " elements and collects the clumps into a new array." }
 | 
			
		||||
{ $errors "Throws an error if " { $snippet "n" } " is larger than the length of the sequence." }
 | 
			
		||||
{ $notes "If the sequence length is smaller than " { $snippet "n" } ", the result will be an array with one element: the original sequence " { $snippet "seq" } "." }
 | 
			
		||||
{ $examples
 | 
			
		||||
    { $example "USING: grouping prettyprint ;" "{ 3 1 3 3 7 } 2 clump ." "{ { 3 1 } { 1 3 } { 3 3 } { 3 7 } }" }
 | 
			
		||||
} ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,8 +12,8 @@ IN: grouping.tests
 | 
			
		|||
    >array
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
[ 0 ] [ { } 2 <clumps> length ] unit-test
 | 
			
		||||
[ 0 ] [ { 1 } 2 <clumps> length ] unit-test
 | 
			
		||||
[ 1 ] [ { } 2 <clumps> length ] unit-test
 | 
			
		||||
[ 1 ] [ { 1 } 2 <clumps> length ] unit-test
 | 
			
		||||
[ 1 ] [ { 1 2 } 2 <clumps> length ] unit-test
 | 
			
		||||
[ 2 ] [ { 1 2 3 } 2 <clumps> length ] unit-test
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,13 +44,13 @@ MIXIN: abstract-clumps
 | 
			
		|||
INSTANCE: abstract-clumps sequence
 | 
			
		||||
 | 
			
		||||
M: abstract-clumps length
 | 
			
		||||
    [ seq>> length 1 + ] [ n>> ] bi [-] ; inline
 | 
			
		||||
    [ seq>> length 1 + ] [ n>> ] bi - 1 max ; inline
 | 
			
		||||
 | 
			
		||||
M: abstract-clumps set-length
 | 
			
		||||
    [ n>> + 1 - ] [ seq>> ] bi set-length ; inline
 | 
			
		||||
 | 
			
		||||
M: abstract-clumps group@
 | 
			
		||||
    [ n>> over + ] [ seq>> ] bi ; inline
 | 
			
		||||
    [ [ n>> over + ] [ seq>> length ] bi min ] [ seq>> ] bi ; inline
 | 
			
		||||
 | 
			
		||||
TUPLE: chunking-seq { seq read-only } { n read-only } ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue