16 lines
448 B
Factor
16 lines
448 B
Factor
USING: arrays fry kernel make sequences ;
|
|
|
|
IN: rosetta-code.multisplit
|
|
|
|
: first-subseq ( seq separators -- n separator )
|
|
tuck
|
|
[ [ subseq-index ] dip 2array ] withd map-index sift-keys
|
|
[ drop f f ] [ [ first ] infimum-by first2 rot nth ] if-empty ;
|
|
|
|
: multisplit ( string separators -- seq )
|
|
'[
|
|
[ dup _ first-subseq dup ] [
|
|
length -rot cut-slice [ , ] dip swap tail-slice
|
|
] while 2drop ,
|
|
] { } make ;
|