rosetta-code.multisplit: reduce memory usage

Avoid creating a filtered sequence when all we need is its first element.
master
Alexander Iljin 2020-04-02 03:15:26 +02:00 committed by John Benediktsson
parent 9b143a826d
commit 7e4c854714
1 changed files with 1 additions and 1 deletions

View File

@ -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