never executed always true always false
    1 module HelVM.HelIO.ListLikeExtra where
    2 
    3 import           HelVM.HelIO.Control.Safe
    4 
    5 import           Data.ListLike
    6 
    7 import           Prelude                  hiding (break, divMod, drop, fromList, length, splitAt, swap, toList, uncons)
    8 
    9 -- | Construction
   10 convert :: (ListLike full1 item , ListLike full2 item) => full1 -> full2
   11 convert = fromList <$> toList
   12 
   13 maybeToFromList :: ListLike full item => Maybe item -> full
   14 maybeToFromList (Just e) = singleton e
   15 maybeToFromList Nothing  = mempty
   16 
   17 -- | Split
   18 splitBy :: (Eq item , ListLike full item) => item -> full -> (full , full)
   19 splitBy separator l =  (acc , drop 1 l') where (acc , l') = break (== separator) l
   20 
   21 -- | Pop
   22 discard :: (MonadSafe m , ListLike full item) => full -> m full
   23 discard l = appendError "Error for discard" $ snd <$> unconsSafe l
   24 
   25 top :: (MonadSafe m , ListLike full item) => full -> m item
   26 top s = appendError "Error for top" $ fst <$> unconsSafe s
   27 
   28 unconsSafe :: (MonadSafe m , ListLike full item) => full -> m (item , full)
   29 unconsSafe = liftMaybeOrError "Empty ListLike for unconsSafe" <$> uncons
   30 
   31 uncons2Safe :: (MonadSafe m , ListLike full item) => full -> m (item , item , full)
   32 uncons2Safe = liftMaybeOrError "Empty ListLike for uncons2Safe" <$> uncons2
   33 
   34 uncons2 :: ListLike full item => full -> Maybe (item, item, full)
   35 uncons2 = uncons2' <=< uncons where
   36   uncons2' (e , l') = uncons2'' <$> uncons l' where
   37     uncons2'' (e' , l'') = (e , e' , l'')