I have written a function
splitAtPredicate that splits the list at element
x and returning a tuple.
-- | 'splitAtPredicate', applied to a predicate @p@ and a list @xs@, -- splits the list at element @x@ satisfying @p@, dropping @x@. splitAtPredicate :: (a -> Bool) -> (a) -> ((a), (a)) splitAtPredicate p = splitAtPredicateAcc p () where splitAtPredicateAcc p left right@(x : xs') | null right = (left, right) | p x = (left, xs') | otherwise = splitAtPredicateAcc p (left ++ (x)) xs'
It works, but I’m new to Haskell, so I’m unsure how idiomatic and performant this is. In addition, I’m not too happy with the name
splitAtPredicateAcc. Any suggestions are more than welcome.