{-# LANGUAGE FlexibleContexts #-}
module Data.ListLike.Utils
(and, or, sum, product, zip, zipWith, unzip, sequence_, toMonadPlus, list,
intercalate
) where
import Prelude hiding (length, head, last, null, tail, map, filter, concat,
any, lookup, init, all, foldl, foldr, foldl1, foldr1,
maximum, minimum, iterate, span, break, takeWhile,
dropWhile, reverse, zip, zipWith, sequence,
sequence_, mapM, mapM_, concatMap, and, or, sum,
product, repeat, replicate, cycle, take, drop,
splitAt, elem, notElem, unzip, lines, words,
unlines, unwords, foldMap)
import Control.Monad (MonadPlus(..))
import Data.ListLike.Base
import Data.ListLike.FoldableLL
import Data.Monoid
and :: ListLike full Bool => full -> Bool
and :: forall full. ListLike full Bool => full -> Bool
and = forall full item.
ListLike full item =>
(item -> Bool) -> full -> Bool
all (forall a. Eq a => a -> a -> Bool
== Bool
True)
or :: ListLike full Bool => full -> Bool
or :: forall full. ListLike full Bool => full -> Bool
or = forall full item.
ListLike full item =>
(item -> Bool) -> full -> Bool
any (forall a. Eq a => a -> a -> Bool
== Bool
True)
sum :: (Num a, ListLike full a) => full -> a
sum :: forall a full. (Num a, ListLike full a) => full -> a
sum = forall a. Sum a -> a
getSum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall full item m.
(FoldableLL full item, Monoid m) =>
(item -> m) -> full -> m
foldMap forall a. a -> Sum a
Sum
product :: (Num a, ListLike full a) => full -> a
product :: forall a full. (Num a, ListLike full a) => full -> a
product = forall a. Product a -> a
getProduct forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall full item m.
(FoldableLL full item, Monoid m) =>
(item -> m) -> full -> m
foldMap forall a. a -> Product a
Product
unzip :: (ListLike full (itema, itemb),
ListLike ra itema,
ListLike rb itemb) => full -> (ra, rb)
unzip :: forall full itema itemb ra rb.
(ListLike full (itema, itemb), ListLike ra itema,
ListLike rb itemb) =>
full -> (ra, rb)
unzip full
inp = forall full item b.
FoldableLL full item =>
(item -> b -> b) -> b -> full -> b
foldr forall {a} {b}.
(ListLike a (Item a), ListLike b (Item b)) =>
(Item a, Item b) -> (a, b) -> (a, b)
convert (forall full item. ListLike full item => full
empty, forall full item. ListLike full item => full
empty) full
inp
where convert :: (Item a, Item b) -> (a, b) -> (a, b)
convert (Item a
a, Item b
b) (a
as, b
bs) = ((forall full item. ListLike full item => item -> full -> full
cons Item a
a a
as), (forall full item. ListLike full item => item -> full -> full
cons Item b
b b
bs))
toMonadPlus :: (MonadPlus m, ListLike full a) => full -> m (a, full)
toMonadPlus :: forall (m :: * -> *) full a.
(MonadPlus m, ListLike full a) =>
full -> m (a, full)
toMonadPlus = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (m :: * -> *) a. MonadPlus m => m a
mzero forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall full item. ListLike full item => full -> Maybe (item, full)
uncons
list :: ListLike full a => b -> (a -> full -> b) -> full -> b
list :: forall full a b.
ListLike full a =>
b -> (a -> full -> b) -> full -> b
list b
d a -> full -> b
f = forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
d (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> full -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) full a.
(MonadPlus m, ListLike full a) =>
full -> m (a, full)
toMonadPlus
intercalate :: (ListLike a item, ListLike b a)
=> a -> b -> a
intercalate :: forall a item b. (ListLike a item, ListLike b a) => a -> b -> a
intercalate a
x = forall full item full'.
(ListLike full item, ListLike full' full) =>
full' -> full
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall full item. ListLike full item => item -> full -> full
intersperse a
x