Anonymous user
Multisplit: Difference between revisions
Add Factor
Thundergnat (talk | contribs) m (Fix Perl 6 -> Raku in comments) |
(Add Factor) |
||
Line 512:
<code>System.StringSplitOptions.None</code> specifies that empty strings should be included in the result.
=={{header|Factor}}==
<lang factor>USING: arrays fry kernel make sequences ;
IN: rosetta-code.multisplit
: ?pair ( ? x -- {?,x}/f )
over [ 2array ] [ 2drop f ] if ;
: best-separator ( seq -- pos index )
dup [ first ] map infimum '[ first _ = ] filter first first2 ;
: first-subseq ( separators seq -- n separator )
dupd [ swap [ subseq-start ] dip ?pair ] curry map-index sift
[ drop f f ] [ best-separator rot nth ] if-empty ;
: multisplit ( string separators -- seq )
'[
[ _ over first-subseq dup ] [
length -rot cut-slice swap , swap tail-slice
] while 2drop ,
] { } make ;</lang>
{{out}}
<pre>> "a!===b=!=c" { "==" "!=" "=" } multisplit [ >string ] map .
{ "a" "" "b" "" "c" }</pre>
=={{header|FreeBASIC}}==
|