, " Prelude" , :
splitWhen p [] = [[]]
splitWhen p l = uncurry (:) . fmap (splitWhen p . drop 1) . break p $ l
Functor (,) a Control.Arrow.second ( -), (ghci " " GHC.Base "), , Prelude, Haskell.
: base, . second fmap, , -, . unfoldr, Maybe , ( ):
import Control.Applicative ((<$>))
import Control.Arrow (second)
import Data.List (unfoldr)
splitWhen p = unfoldr (second check . break p <$>) . Just
where
check [] = Nothing
check (_:rest) = Just rest
-- or cramming it into a single line with 'Data.Maybe.listToMaybe'
splitWhen' p =
unfoldr (second (\rest -> tail rest <$ listToMaybe rest) . break p <$>) . Just