ListLike 3.1.2 → 3.1.4
raw patch · 7 files changed
+14/−12 lines, 7 filesdep ~arrayPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: array
API changes (from Hackage documentation)
- Data.ListLike: class FoldableLL full item | full -> item
+ Data.ListLike: class FoldableLL full item | full -> item where foldl' f a xs = foldr f' id xs a where f' x k z = k $! f z x foldl1 f xs = fromMaybe (error "fold1: empty structure") (foldl mf Nothing xs) where mf Nothing y = Just y mf (Just x) y = Just (f x y) foldr' f a xs = foldl f' id xs a where f' k x z = k $! f x z foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x Nothing = Just x mf x (Just y) = Just (f x y)
- Data.ListLike: class ListLike full item => InfiniteListLike full item | full -> item
+ Data.ListLike: class ListLike full item => InfiniteListLike full item | full -> item where iterate f x = cons x (iterate f (f x)) repeat x = xs where xs = cons x xs cycle xs | null xs = error "ListLike.cycle: empty list" | otherwise = xs' where xs' = append xs xs'
- Data.ListLike: class (FoldableLL full item, Monoid full) => ListLike full item | full -> item
+ Data.ListLike: class (FoldableLL full item, Monoid full) => ListLike full item | full -> item where empty = mempty cons item l = append (singleton item) l snoc l item = append l (singleton item) append = mappend last l = case genericLength l of { (0 :: Integer) -> error "Called last on empty list" 1 -> head l _ -> last (tail l) } init l | null l = error "init: empty list" | null xs = empty | otherwise = cons (head l) (init xs) where xs = tail l null x = genericLength x == (0 :: Integer) length = genericLength map func inp | null inp = empty | otherwise = cons (func (head inp)) (map func (tail inp)) rigidMap = map reverse l = rev l empty where rev rl a | null rl = a | otherwise = rev (tail rl) (cons (head rl) a) intersperse sep l | null l = empty | null xs = singleton x | otherwise = cons x (cons sep (intersperse sep xs)) where x = head l xs = tail l concat = fold concatMap = foldMap rigidConcatMap = concatMap any p = getAny . foldMap (Any . p) all p = getAll . foldMap (All . p) maximum = foldr1 max minimum = foldr1 min replicate = genericReplicate take = genericTake drop = genericDrop splitAt = genericSplitAt takeWhile func l | null l = empty | func x = cons x (takeWhile func (tail l)) | otherwise = empty where x = head l dropWhile func l | null l = empty | func (head l) = dropWhile func (tail l) | otherwise = l span func l | null l = (empty, empty) | func x = (cons x ys, zs) | otherwise = (empty, l) where (ys, zs) = span func (tail l) x = head l break p = span (not . p) group = groupBy (==) inits l | null l = singleton empty | otherwise = append (singleton empty) (map (cons (head l)) theinits) where theinits = asTypeOf (inits (tail l)) [l] tails l | null l = singleton empty | otherwise = cons l (tails (tail l)) isPrefixOf needle haystack | null needle = True | null haystack = False | otherwise = (head needle) == (head haystack) && isPrefixOf (tail needle) (tail haystack) isSuffixOf needle haystack = isPrefixOf (reverse needle) (reverse haystack) isInfixOf needle haystack = any (isPrefixOf needle) thetails where thetails = asTypeOf (tails haystack) [haystack] elem i = any (== i) notElem i = all (/= i) find f l = case findIndex f l of { Nothing -> Nothing Just x -> Just (index l x) } filter func l | null l = empty | func (head l) = cons (head l) (filter func (tail l)) | otherwise = filter func (tail l) partition p xs = (filter p xs, filter (not . p) xs) index l i | null l = error "index: index not found" | i < 0 = error "index: index must be >= 0" | i == 0 = head l | otherwise = index (tail l) (i - 1) elemIndex e l = findIndex (== e) l elemIndices i l = findIndices (== i) l findIndex f = listToMaybe . findIndices f findIndices p xs = map snd $ filter (p . fst) $ thezips where thezips = asTypeOf (zip xs [0 .. ]) [(head xs, 0 :: Int)] sequence l = foldr func (return empty) l where func litem results = do { x <- litem; xs <- results; return (cons x xs) } mapM func l = sequence mapresult where mapresult = asTypeOf (map func l) [] rigidMapM = mapM mapM_ func l = sequence_ mapresult where mapresult = asTypeOf (map func l) [] nub = nubBy (==) delete = deleteBy (==) deleteFirsts = foldl (flip delete) union = unionBy (==) intersect = intersectBy (==) sort = sortBy compare insert = insertBy compare toList = fromListLike fromList [] = empty fromList (x : xs) = cons x (fromList xs) fromListLike = map id nubBy f l = nubBy' l (empty :: full) where nubBy' ys xs | null ys = empty | any (f (head ys)) xs = nubBy' (tail ys) xs | otherwise = let y = head ys in cons y (nubBy' (tail ys) (cons y xs)) deleteBy func i l | null l = empty | otherwise = if func i (head l) then tail l else cons (head l) (deleteBy func i (tail l)) deleteFirstsBy func = foldl (flip (deleteBy func)) unionBy func x y = append x $ foldl (flip (deleteBy func)) (nubBy func y) x intersectBy func xs ys = filter (\ x -> any (func x) ys) xs groupBy eq l | null l = empty | otherwise = cons (cons x ys) (groupBy eq zs) where (ys, zs) = span (eq x) xs x = head l xs = tail l sortBy cmp = foldr (insertBy cmp) empty insertBy cmp x ys | null ys = singleton x | otherwise = case cmp x (head ys) of { GT -> cons (head ys) (insertBy cmp x (tail ys)) _ -> cons x ys } genericLength l = calclen 0 l where calclen !accum cl = if null cl then accum else calclen (accum + 1) (tail cl) genericTake n l | n <= 0 = empty | null l = empty | otherwise = cons (head l) (genericTake (n - 1) (tail l)) genericDrop n l | n <= 0 = l | null l = l | otherwise = genericDrop (n - 1) (tail l) genericSplitAt n l = (genericTake n l, genericDrop n l) genericReplicate count x | count <= 0 = empty | otherwise = map (\ _ -> x) [1 .. count]
- Data.ListLike: class ListLike full item => ListLikeIO full item | full -> item
+ Data.ListLike: class ListLike full item => ListLikeIO full item | full -> item where hPutStrLn fp x = do { hPutStr fp x; hPutStrLn fp "" } getLine = hGetLine stdin getContents = hGetContents stdin putStr = hPutStr stdout putStrLn = hPutStrLn stdout interact func = do { c <- getContents; putStr (func c) } readFile fn = do { fp <- openFile fn ReadMode; hGetContents fp } writeFile fn x = do { fp <- openFile fn WriteMode; hPutStr fp x; hClose fp } appendFile fn x = do { fp <- openFile fn AppendMode; hPutStr fp x; hClose fp }
- Data.ListLike: class StringLike s
+ Data.ListLike: class StringLike s where lines = myLines words = myWords unlines = myUnlines unwords = myUnwords
- Data.ListLike.Base: class ListLike full item => InfiniteListLike full item | full -> item
+ Data.ListLike.Base: class ListLike full item => InfiniteListLike full item | full -> item where iterate f x = cons x (iterate f (f x)) repeat x = xs where xs = cons x xs cycle xs | null xs = error "ListLike.cycle: empty list" | otherwise = xs' where xs' = append xs xs'
- Data.ListLike.Base: class (FoldableLL full item, Monoid full) => ListLike full item | full -> item
+ Data.ListLike.Base: class (FoldableLL full item, Monoid full) => ListLike full item | full -> item where empty = mempty cons item l = append (singleton item) l snoc l item = append l (singleton item) append = mappend last l = case genericLength l of { (0 :: Integer) -> error "Called last on empty list" 1 -> head l _ -> last (tail l) } init l | null l = error "init: empty list" | null xs = empty | otherwise = cons (head l) (init xs) where xs = tail l null x = genericLength x == (0 :: Integer) length = genericLength map func inp | null inp = empty | otherwise = cons (func (head inp)) (map func (tail inp)) rigidMap = map reverse l = rev l empty where rev rl a | null rl = a | otherwise = rev (tail rl) (cons (head rl) a) intersperse sep l | null l = empty | null xs = singleton x | otherwise = cons x (cons sep (intersperse sep xs)) where x = head l xs = tail l concat = fold concatMap = foldMap rigidConcatMap = concatMap any p = getAny . foldMap (Any . p) all p = getAll . foldMap (All . p) maximum = foldr1 max minimum = foldr1 min replicate = genericReplicate take = genericTake drop = genericDrop splitAt = genericSplitAt takeWhile func l | null l = empty | func x = cons x (takeWhile func (tail l)) | otherwise = empty where x = head l dropWhile func l | null l = empty | func (head l) = dropWhile func (tail l) | otherwise = l span func l | null l = (empty, empty) | func x = (cons x ys, zs) | otherwise = (empty, l) where (ys, zs) = span func (tail l) x = head l break p = span (not . p) group = groupBy (==) inits l | null l = singleton empty | otherwise = append (singleton empty) (map (cons (head l)) theinits) where theinits = asTypeOf (inits (tail l)) [l] tails l | null l = singleton empty | otherwise = cons l (tails (tail l)) isPrefixOf needle haystack | null needle = True | null haystack = False | otherwise = (head needle) == (head haystack) && isPrefixOf (tail needle) (tail haystack) isSuffixOf needle haystack = isPrefixOf (reverse needle) (reverse haystack) isInfixOf needle haystack = any (isPrefixOf needle) thetails where thetails = asTypeOf (tails haystack) [haystack] elem i = any (== i) notElem i = all (/= i) find f l = case findIndex f l of { Nothing -> Nothing Just x -> Just (index l x) } filter func l | null l = empty | func (head l) = cons (head l) (filter func (tail l)) | otherwise = filter func (tail l) partition p xs = (filter p xs, filter (not . p) xs) index l i | null l = error "index: index not found" | i < 0 = error "index: index must be >= 0" | i == 0 = head l | otherwise = index (tail l) (i - 1) elemIndex e l = findIndex (== e) l elemIndices i l = findIndices (== i) l findIndex f = listToMaybe . findIndices f findIndices p xs = map snd $ filter (p . fst) $ thezips where thezips = asTypeOf (zip xs [0 .. ]) [(head xs, 0 :: Int)] sequence l = foldr func (return empty) l where func litem results = do { x <- litem; xs <- results; return (cons x xs) } mapM func l = sequence mapresult where mapresult = asTypeOf (map func l) [] rigidMapM = mapM mapM_ func l = sequence_ mapresult where mapresult = asTypeOf (map func l) [] nub = nubBy (==) delete = deleteBy (==) deleteFirsts = foldl (flip delete) union = unionBy (==) intersect = intersectBy (==) sort = sortBy compare insert = insertBy compare toList = fromListLike fromList [] = empty fromList (x : xs) = cons x (fromList xs) fromListLike = map id nubBy f l = nubBy' l (empty :: full) where nubBy' ys xs | null ys = empty | any (f (head ys)) xs = nubBy' (tail ys) xs | otherwise = let y = head ys in cons y (nubBy' (tail ys) (cons y xs)) deleteBy func i l | null l = empty | otherwise = if func i (head l) then tail l else cons (head l) (deleteBy func i (tail l)) deleteFirstsBy func = foldl (flip (deleteBy func)) unionBy func x y = append x $ foldl (flip (deleteBy func)) (nubBy func y) x intersectBy func xs ys = filter (\ x -> any (func x) ys) xs groupBy eq l | null l = empty | otherwise = cons (cons x ys) (groupBy eq zs) where (ys, zs) = span (eq x) xs x = head l xs = tail l sortBy cmp = foldr (insertBy cmp) empty insertBy cmp x ys | null ys = singleton x | otherwise = case cmp x (head ys) of { GT -> cons (head ys) (insertBy cmp x (tail ys)) _ -> cons x ys } genericLength l = calclen 0 l where calclen !accum cl = if null cl then accum else calclen (accum + 1) (tail cl) genericTake n l | n <= 0 = empty | null l = empty | otherwise = cons (head l) (genericTake (n - 1) (tail l)) genericDrop n l | n <= 0 = l | null l = l | otherwise = genericDrop (n - 1) (tail l) genericSplitAt n l = (genericTake n l, genericDrop n l) genericReplicate count x | count <= 0 = empty | otherwise = map (\ _ -> x) [1 .. count]
- Data.ListLike.FoldableLL: class FoldableLL full item | full -> item
+ Data.ListLike.FoldableLL: class FoldableLL full item | full -> item where foldl' f a xs = foldr f' id xs a where f' x k z = k $! f z x foldl1 f xs = fromMaybe (error "fold1: empty structure") (foldl mf Nothing xs) where mf Nothing y = Just y mf (Just x) y = Just (f x y) foldr' f a xs = foldl f' id xs a where f' k x z = k $! f x z foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x Nothing = Just x mf x (Just y) = Just (f x y)
- Data.ListLike.IO: class ListLike full item => ListLikeIO full item | full -> item
+ Data.ListLike.IO: class ListLike full item => ListLikeIO full item | full -> item where hPutStrLn fp x = do { hPutStr fp x; hPutStrLn fp "" } getLine = hGetLine stdin getContents = hGetContents stdin putStr = hPutStr stdout putStrLn = hPutStrLn stdout interact func = do { c <- getContents; putStr (func c) } readFile fn = do { fp <- openFile fn ReadMode; hGetContents fp } writeFile fn x = do { fp <- openFile fn WriteMode; hPutStr fp x; hClose fp } appendFile fn x = do { fp <- openFile fn AppendMode; hPutStr fp x; hClose fp }
- Data.ListLike.String: class StringLike s
+ Data.ListLike.String: class StringLike s where lines = myLines words = myWords unlines = myUnlines unwords = myUnwords
Files
- ListLike.cabal +2/−2
- src/Data/ListLike/Base.hs +1/−1
- src/Data/ListLike/FoldableLL.hs +1/−1
- src/Data/ListLike/IO.hs +1/−1
- src/Data/ListLike/Instances.hs +7/−5
- src/Data/ListLike/String.hs +1/−1
- src/Data/ListLike/Utils.hs +1/−1
ListLike.cabal view
@@ -1,5 +1,5 @@ Name: ListLike-Version: 3.1.2+Version: 3.1.4 License: BSD3 Maintainer: John Lato <jwlato@gmail.com> Author: John Goerzen@@ -37,7 +37,7 @@ Build-Depends: base >= 3 && < 5 ,containers >= 0.3 && < 0.5 ,bytestring >= 0.9.1 && < 0.10- ,array >= 0.3 && < 0.4+ ,array >= 0.3 && < 0.5 Executable runtests Buildable: False
src/Data/ListLike/Base.hs view
@@ -19,7 +19,7 @@ Copyright : Copyright (C) 2007 John Goerzen License : BSD3 - Maintainer : John Goerzen <jgoerzen@complete.org>+ Maintainer : John Lato <jwlato@gmail.com> Stability : provisional Portability: portable
src/Data/ListLike/FoldableLL.hs view
@@ -15,7 +15,7 @@ Copyright : Copyright (C) 2007 John Goerzen License : BSD3 - Maintainer : John Goerzen <jgoerzen@complete.org>+ Maintainer : John Lato <jwlato@gmail.com> Stability : provisional Portability: portable
src/Data/ListLike/IO.hs view
@@ -16,7 +16,7 @@ Copyright : Copyright (C) 2007 John Goerzen License : BSD3 - Maintainer : John Goerzen <jgoerzen@complete.org>+ Maintainer : John Lato <jwlato@gmail.com> Stability : provisional Portability: portable
src/Data/ListLike/Instances.hs view
@@ -17,7 +17,7 @@ Copyright : Copyright (C) 2007 John Goerzen License : BSD3 - Maintainer : John Goerzen <jgoerzen@complete.org>+ Maintainer : John Lato <jwlato@gmail.com> Stability : provisional Portability: portable @@ -47,11 +47,13 @@ import Data.Int import Data.Monoid import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as BSC import qualified Data.Foldable as F import qualified Data.Traversable as T import qualified Data.Array.IArray as A import Data.Array.IArray((!), (//), Ix(..)) import qualified Data.ByteString.Lazy as BSL+import qualified Data.ByteString.Lazy.Char8 as BSLC import qualified System.IO as IO import Data.Word @@ -176,11 +178,11 @@ hGet = BS.hGet hGetNonBlocking = BS.hGetNonBlocking hPutStr = BS.hPutStr- hPutStrLn = BS.hPutStrLn+ hPutStrLn = BSC.hPutStrLn getLine = BS.getLine getContents = BS.getContents putStr = BS.putStr- putStrLn = BS.putStrLn+ putStrLn = BSC.putStrLn interact = BS.interact readFile = BS.readFile writeFile = BS.writeFile@@ -289,11 +291,11 @@ hGet = BSL.hGet hGetNonBlocking = BSL.hGetNonBlocking hPutStr = BSL.hPut- --hPutStrLn = BSL.hPutStrLn+ -- hPutStrLn = BSLC.hPutStrLn getLine = BS.getLine >>= strict2lazy getContents = BSL.getContents putStr = BSL.putStr- putStrLn = BSL.putStrLn+ putStrLn = BSLC.putStrLn interact = BSL.interact readFile = BSL.readFile writeFile = BSL.writeFile
src/Data/ListLike/String.hs view
@@ -12,7 +12,7 @@ Copyright : Copyright (C) 2007 John Goerzen License : BSD3 - Maintainer : John Goerzen <jgoerzen@complete.org>+ Maintainer : John Lato <jwlato@gmail.com> Stability : provisional Portability: portable
src/Data/ListLike/Utils.hs view
@@ -15,7 +15,7 @@ Copyright : Copyright (C) 2007 John Goerzen License : BSD3 - Maintainer : John Goerzen <jgoerzen@complete.org>+ Maintainer : John Lato <jwlato@gmail.com> Stability : provisional Portability: portable