module Text.XML.Basic.Utility where
import Data.List.HT (switchL, break, )
import Data.Tuple.HT (mapSnd, )
import Prelude hiding (break, )
updateAppend :: (a -> Bool) -> a -> (a -> a) -> [a] -> [a]
updateAppend p deflt f =
uncurry (++) .
mapSnd (uncurry (:) . switchL (deflt,[]) ((,) . f)) .
break p
updateAppend' :: (a -> Bool) -> a -> (a -> a) -> [a] -> [a]
updateAppend' p deflt f =
let recourse xt =
uncurry (:) $
case xt of
[] -> (deflt,[])
(x:xs) ->
if p x
then (f x, xs)
else (x, recourse xs)
in recourse