packages feed

fmlist 0.1.1 → 0.2

raw patch · 2 files changed

+58/−50 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.FMList: fromFoldable :: (Foldable f) => f a -> FMList a

Files

Data/FMList.hs view
@@ -26,6 +26,7 @@      , toList   , fromList+  , fromFoldable      , null   , head@@ -66,88 +67,95 @@  newtype FMList a = FM { unFM :: forall b . Monoid b => (a -> b) -> b } --- Moved to Alternative instance--- empty       :: FMList a--- empty       = FM $ \f -> mempty+-- nil is exported as empty from Applicative+nil          :: FMList a+nil          = FM $ \f -> mempty -singleton   :: a -> FMList a-singleton x = FM $ \f -> f x+singleton    :: a -> FMList a+singleton x  = FM $ \f -> f x -cons        :: a -> FMList a -> FMList a-cons x l    = FM $ \f -> f x `mappend` unFM l f+cons         :: a -> FMList a -> FMList a+cons x l     = FM $ \f -> f x `mappend` unFM l f -snoc        :: FMList a -> a -> FMList a-snoc l x    = FM $ \f -> unFM l f `mappend` f x+snoc         :: FMList a -> a -> FMList a+snoc l x     = FM $ \f -> unFM l f `mappend` f x -append      :: FMList a -> FMList a -> FMList a+append       :: FMList a -> FMList a -> FMList a -- append l r  = FM $ \f -> unFM l f `mappend` unFM r f-append l r  = FM $ unFM l `mappend` unFM r+append l r   = FM $ unFM l `mappend` unFM r -flatten     :: FMList (FMList a) -> FMList a-flatten l   = FM $ \f -> unFM l (foldMap f)+flatten      :: FMList (FMList a) -> FMList a+-- flatten l    = FM $ \f -> unFM l (foldMap f)+flatten l    = FM $ unFM l . foldMap -fromList    :: [a] -> FMList a-fromList    = unfoldr listSplit where-  listSplit [] = Nothing-  listSplit (x:xs) = Just (x, xs) -null :: FMList a -> Bool-null = foldr (\_ _ -> False) True+fromList     :: [a] -> FMList a+fromList     = fromFoldable -head :: FMList a -> a-head l = getFirst (unFM l (First . Just)) `fromJustOrError` "Data.FMList.head: empty list"+fromFoldable :: Foldable f => f a -> FMList a+fromFoldable l = FM $ flip foldMap l -tail :: FMList a -> FMList a-tail l = if null l then error "Data.FMList.tail: empty list" else drop 1 l -last :: FMList a -> a-last l = getLast (unFM l (Last . Just)) `fromJustOrError` "Data.FMList.last: empty list"+null         :: FMList a -> Bool+null         = foldr (\_ _ -> False) True -init :: FMList a -> FMList a-init l = if null l then error "Data.FMList.init: empty list" else reverse . drop 1 . reverse $ l+head         :: FMList a -> a+head l       = getFirst (unFM l (First . Just)) `fromJustOrError` "Data.FMList.head: empty list" -reverse :: FMList a -> FMList a-reverse l = FM $ \f -> getDual $ unFM l (Dual . f)+tail         :: FMList a -> FMList a+tail l       = if null l then error "Data.FMList.tail: empty list" else drop 1 l -filter :: (a -> Bool) -> FMList a -> FMList a-filter p l = FM $ \f -> unFM l $ \e -> if p e then f e else mempty+last         :: FMList a -> a+last l       = getLast (unFM l (Last . Just)) `fromJustOrError` "Data.FMList.last: empty list" -take :: (Ord n, Num n) => n -> FMList a -> FMList a-take n l = FM $ \f -> +init         :: FMList a -> FMList a+init l       = if null l then error "Data.FMList.init: empty list" else reverse . drop 1 . reverse $ l++reverse      :: FMList a -> FMList a+reverse l    = FM $ \f -> getDual $ unFM l (Dual . f)+++filter       :: (a -> Bool) -> FMList a -> FMList a+filter p l   = FM $ \f -> unFM l $ \e -> if p e then f e else mempty++take         :: (Ord n, Num n) => n -> FMList a -> FMList a+take n l     = FM $ \f ->    foldr (\e r i -> if i > 0 then mappend (f e) (r (i-1)) else mempty) (const mempty) l n -drop :: (Ord n, Num n) => n -> FMList a -> FMList a-drop n l = FM $ \f -> +drop         :: (Ord n, Num n) => n -> FMList a -> FMList a+drop n l     = FM $ \f ->    foldr (\e r i -> if i <= 0 then mappend (f e) (r i) else r (i-1)) (const mempty) l n -takeWhile :: (a -> Bool) -> FMList a -> FMList a+takeWhile    :: (a -> Bool) -> FMList a -> FMList a takeWhile p l = FM $ \f ->    foldr (\e r -> if p e then mappend (f e) r else mempty) mempty l -dropWhile :: (a -> Bool) -> FMList a -> FMList a+dropWhile    :: (a -> Bool) -> FMList a -> FMList a dropWhile p l = FM $ \f ->    foldr (\e r done -> if done || not (p e) then mappend (f e) (r True) else r False) (const mempty) l False -zipWith :: (a -> b -> c) -> FMList a -> FMList b -> FMList c++zipWith      :: (a -> b -> c) -> FMList a -> FMList b -> FMList c zipWith t l1 l2 = FM $ \f ->    foldr (\e1 r r2 ->  	  foldr (\e2 _ -> mappend (f (t e1 e2)) (r (drop 1 r2))) mempty r2) (const mempty) l1 l2 -zip :: FMList a -> FMList b -> FMList (a,b)-zip = zipWith (,)+zip          :: FMList a -> FMList b -> FMList (a,b)+zip          = zipWith (,) -iterate :: (a -> a) -> a -> FMList a-iterate f x = x `cons` iterate f (f x) -repeat :: a -> FMList a-repeat x = xs where xs = x `cons` xs+iterate      :: (a -> a) -> a -> FMList a+iterate f x  = x `cons` iterate f (f x) -unfoldr :: (b -> Maybe (a, b)) -> b -> FMList a+repeat       :: a -> FMList a+repeat x     = xs where xs = x `cons` xs++unfoldr      :: (b -> Maybe (a, b)) -> b -> FMList a unfoldr pf b = FM $ \f -> u f mempty (pf b) where   u _ acc Nothing = acc   u f acc (Just (a, b')) = u f (acc `mappend` f a) (pf b') -unfoldl :: (b -> Maybe (b, a)) -> b -> FMList a+unfoldl      :: (b -> Maybe (b, a)) -> b -> FMList a unfoldl pf b = FM $ \f -> u f mempty (pf b) where   u _ acc Nothing = acc   u f acc (Just (b', a)) = u f (f a `mappend` acc) (pf b')@@ -171,15 +179,15 @@   (<*>)    = ap      instance Monoid (FMList a) where-  mempty   = empty+  mempty   = nil   mappend  = append    instance MonadPlus FMList where-  mzero    = empty+  mzero    = nil   mplus    = append    instance Alternative FMList where-  empty    = FM $ \_ -> mempty+  empty    = nil   (<|>)    = append    instance Show a => Show (FMList a) where
fmlist.cabal view
@@ -1,5 +1,5 @@ name:                fmlist-version:             0.1.1+version:             0.2 synopsis:            FoldMap lists description:            FoldMap lists are lists represented by their foldMap function.