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