module Simulation.Aivika.Experiment.Utils
(divideBy, replace) where
import Data.List
import Data.List.Split
divideBy :: (a -> Bool) -> [a] -> [[a]]
divideBy :: forall a. (a -> Bool) -> [a] -> [[a]]
divideBy a -> Bool
p [a]
xs =
case forall a. (a -> Bool) -> [a] -> [a]
dropWhile a -> Bool
p [a]
xs of
[] -> []
[a]
xs' -> [a]
ys forall a. a -> [a] -> [a]
: forall a. (a -> Bool) -> [a] -> [[a]]
divideBy a -> Bool
p [a]
xs''
where ([a]
ys, [a]
xs'') = forall a. (a -> Bool) -> [a] -> ([a], [a])
break a -> Bool
p [a]
xs'
replace :: String -> String -> String -> String
replace :: String -> String -> String -> String
replace String
old String
new = forall a. [a] -> [[a]] -> [a]
intercalate String
new forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
old