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 (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile a -> Bool
p [a]
xs of
[] -> []
[a]
xs' -> [a]
ys [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: (a -> Bool) -> [a] -> [[a]]
forall a. (a -> Bool) -> [a] -> [[a]]
divideBy a -> Bool
p [a]
xs''
where ([a]
ys, [a]
xs'') = (a -> Bool) -> [a] -> ([a], [a])
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 = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
new ([String] -> String) -> (String -> [String]) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> [String]
forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
old