Multisplit: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: (Replaced one If with a `case ... of`)) |
|||
Line 676:
Or as a fold:
<lang haskell>
multiSplit ds s =
let lng = length s
(
foldl
(\(tokens, parts, offset) (c, i) ->
let inDelim = offset > i
in case (if
Just x ->
([], [], 0)
(zip s [0 .. lng])
in mappend
main :: IO ()
main = print $ multiSplit ["==", "!=", "="] "a!===b=!=c"</lang>
{{Out}}
<pre>[("a","!=",1),("","==",3),("b","=",6),("","!=",7),("c","",10)]</pre>
|