Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Multisplit/Haskell/multisplit-2.hs
Normal file
18
Task/Multisplit/Haskell/multisplit-2.hs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import Data.List (find, isPrefixOf, foldl') --'
|
||||
import Data.Bool (bool)
|
||||
|
||||
multiSplit :: [String] -> String -> [(String, String, Int)]
|
||||
multiSplit ds s =
|
||||
let (ts, ps, o) =
|
||||
foldl' --'
|
||||
(\(tokens, parts, offset) (c, i) ->
|
||||
let inDelim = offset > i
|
||||
in maybe
|
||||
(bool (c : tokens) tokens inDelim, parts, offset)
|
||||
(\x -> ([], (tokens, x, i) : parts, i + length x))
|
||||
(bool (find (`isPrefixOf` drop i s) ds) Nothing inDelim))
|
||||
([], [], 0)
|
||||
(zip s [0 ..])
|
||||
in reverse $ (ts, [], length s) : ps
|
||||
main :: IO ()
|
||||
main = print $ multiSplit ["==", "!=", "="] "a!===b=!=c"
|
||||
Loading…
Add table
Add a link
Reference in a new issue