RosettaCodeData/Task/Multisplit/Factor/multisplit.factor

16 lines
448 B
Factor
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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 ;