rosetta-code.multisplit: reduce memory usage
Avoid creating a filtered sequence when all we need is its first element.master
parent
9b143a826d
commit
7e4c854714
|
@ -8,7 +8,7 @@ IN: rosetta-code.multisplit
|
||||||
over [ 2array ] [ 2drop f ] if ;
|
over [ 2array ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: best-separator ( seq -- pos index )
|
: best-separator ( seq -- pos index )
|
||||||
dup [ first ] map infimum '[ first _ = ] filter first first2 ;
|
dup [ first ] map infimum '[ first _ = ] find nip first2 ;
|
||||||
|
|
||||||
: first-subseq ( separators seq -- n separator )
|
: first-subseq ( separators seq -- n separator )
|
||||||
dupd [ swap [ subseq-start ] dip ?pair ] curry map-index sift
|
dupd [ swap [ subseq-start ] dip ?pair ] curry map-index sift
|
||||||
|
|
Loading…
Reference in New Issue