mono-traversable 0.7.0 → 0.8.0
raw patch · 4 files changed
+112/−60 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.MonoTraversable: class (MonoFoldable mono, Eq (Element mono)) => MonoFoldableEq mono where oelem e = elem e . otoList onotElem e = notElem e . otoList
+ Data.MonoTraversable: instance (Eq a, Ord a) => MonoFoldableEq (Set a)
+ Data.MonoTraversable: instance (Eq a, Storable a) => MonoFoldableEq (Vector a)
+ Data.MonoTraversable: instance (Eq a, Unbox a) => MonoFoldableEq (Vector a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (DList a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (HashSet a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (Identity a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (IntMap a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (Maybe a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (NonEmpty a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (Option a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (Seq a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (Tree a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (Vector a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (ViewL a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq (ViewR a)
+ Data.MonoTraversable: instance Eq a => MonoFoldableEq [a]
+ Data.MonoTraversable: instance Eq b => MonoFoldableEq (Either a b)
+ Data.MonoTraversable: instance Eq v => MonoFoldableEq (HashMap k v)
+ Data.MonoTraversable: instance Eq v => MonoFoldableEq (Map k v)
+ Data.MonoTraversable: instance MonoFoldableEq ByteString
+ Data.MonoTraversable: instance MonoFoldableEq IntSet
+ Data.MonoTraversable: instance MonoFoldableEq Text
+ Data.MonoTraversable: oelem :: MonoFoldableEq mono => Element mono -> mono -> Bool
+ Data.MonoTraversable: onotElem :: MonoFoldableEq mono => Element mono -> mono -> Bool
- Data.Sequences: class (IsSequence seq, Eq (Element seq)) => EqSequence seq where stripPrefix x y = fmap fromList (otoList x `stripPrefix` otoList y) isPrefixOf x y = otoList x `isPrefixOf` otoList y stripSuffix x y = fmap fromList (otoList x `stripSuffix` otoList y) isSuffixOf x y = otoList x `isSuffixOf` otoList y isInfixOf x y = otoList x `isInfixOf` otoList y group = groupBy (==) groupAll = groupAllOn id elem e = elem e . otoList notElem e = notElem e . otoList
+ Data.Sequences: class (MonoFoldableEq seq, IsSequence seq, Eq (Element seq)) => EqSequence seq where stripPrefix x y = fmap fromList (otoList x `stripPrefix` otoList y) stripSuffix x y = fmap fromList (otoList x `stripSuffix` otoList y) isPrefixOf x y = otoList x `isPrefixOf` otoList y isSuffixOf x y = otoList x `isSuffixOf` otoList y isInfixOf x y = otoList x `isInfixOf` otoList y group = groupBy (==) groupAll = groupAllOn id
Files
- ChangeLog.md +9/−0
- mono-traversable.cabal +1/−1
- src/Data/MonoTraversable.hs +62/−3
- src/Data/Sequences.hs +40/−56
ChangeLog.md view
@@ -1,3 +1,12 @@+## 0.8.0++A new MonoFoldableEq class that takes `elem` and `notElem` from `EqSequence`.+`EqSequence` now inherits from `MonoFoldableEq`.++For most users that do not define instances this should not be a breaking change.+However, any instance of `EqSequence` now needs to definie `MonoFoldableEq`.++ ## 0.7.0 * Work on better polymorphic containers
mono-traversable.cabal view
@@ -1,5 +1,5 @@ name: mono-traversable-version: 0.7.0+version: 0.8.0 synopsis: Type classes for mapping, folding, and traversing monomorphic containers description: Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. If you understand Haskell's basic typeclasses, you understand mono-traversable. In addition to what you are used to, it adds on an IsSequence typeclass and has code for marking data structures as non-empty. homepage: https://github.com/snoyberg/mono-traversable
src/Data/MonoTraversable.hs view
@@ -36,9 +36,9 @@ import Data.Word (Word8) import Data.Int (Int, Int64) import GHC.Exts (build)-import Prelude (Bool (..), const, Char, flip, ($), IO, Maybe (..), Either (..),- replicate, (+), Integral, Ordering (..), compare, fromIntegral, Num, (>=),- seq, otherwise, maybe, Ord, (-), (*))+import Prelude (Bool (..), const, Char, flip, IO, Maybe (..), Either (..),+ (+), Integral, Ordering (..), compare, fromIntegral, Num, (>=),+ seq, otherwise, maybe, Eq, Ord, (-), (*)) import qualified Prelude import qualified Data.ByteString.Internal as Unsafe import qualified Foreign.ForeignPtr.Unsafe as Unsafe@@ -52,6 +52,7 @@ import Data.IntMap (IntMap) import Data.IntSet (IntSet) import Data.Semigroup (Option)+import qualified Data.List as List import Data.List.NonEmpty (NonEmpty) import Data.Functor.Identity (Identity) import Data.Map (Map)@@ -693,6 +694,64 @@ instance MonoFoldableMonoid TL.Text where oconcatMap = TL.concatMap {-# INLINE oconcatMap #-}++-- | A typeclass for @MonoFoldable@s containing elements which are an instance+-- of @Eq@.+class (MonoFoldable mono, Eq (Element mono)) => MonoFoldableEq mono where+ oelem :: Element mono -> mono -> Bool+ oelem e = List.elem e . otoList++ onotElem :: Element mono -> mono -> Bool+ onotElem e = List.notElem e . otoList+ {-# INLINE oelem #-}+ {-# INLINE onotElem #-}++instance Eq a => MonoFoldableEq (Seq.Seq a)+instance Eq a => MonoFoldableEq (V.Vector a)+instance (Eq a, U.Unbox a) => MonoFoldableEq (U.Vector a)+instance (Eq a, VS.Storable a) => MonoFoldableEq (VS.Vector a)+instance Eq a => MonoFoldableEq (NonEmpty a)+instance MonoFoldableEq T.Text+instance MonoFoldableEq TL.Text+instance MonoFoldableEq IntSet+instance Eq a => MonoFoldableEq (Maybe a) +instance Eq a => MonoFoldableEq (Tree a)+instance Eq a => MonoFoldableEq (ViewL a)+instance Eq a => MonoFoldableEq (ViewR a)+instance Eq a => MonoFoldableEq (IntMap a)+instance Eq a => MonoFoldableEq (Option a)+instance Eq a => MonoFoldableEq (Identity a)+instance Eq v => MonoFoldableEq (Map k v)+instance Eq v => MonoFoldableEq (HashMap k v)+instance Eq a => MonoFoldableEq (HashSet a)+instance Eq a => MonoFoldableEq (DList a)+instance Eq b => MonoFoldableEq (Either a b)+++instance Eq a => MonoFoldableEq [a] where+ oelem = List.elem+ onotElem = List.notElem+ {-# INLINE oelem #-}+ {-# INLINE onotElem #-}++instance MonoFoldableEq S.ByteString where+ oelem = S.elem+ onotElem = S.notElem+ {-# INLINE oelem #-}+ {-# INLINE onotElem #-}++instance MonoFoldableEq L.ByteString where+ oelem = L.elem+ onotElem = L.notElem+ {-# INLINE oelem #-}+ {-# INLINE onotElem #-}++instance (Eq a, Ord a) => MonoFoldableEq (Set a) where+ oelem = Set.member+ onotElem = Set.notMember+ {-# INLINE oelem #-}+ {-# INLINE onotElem #-}+ -- | A typeclass for @MonoFoldable@s containing elements which are an instance -- of @Ord@.
src/Data/Sequences.hs view
@@ -945,16 +945,16 @@ {-# INLINE indexEx #-} {-# INLINE unsafeIndex #-} -class (IsSequence seq, Eq (Element seq)) => EqSequence seq where+class (MonoFoldableEq seq, IsSequence seq, Eq (Element seq)) => EqSequence seq where stripPrefix :: seq -> seq -> Maybe seq stripPrefix x y = fmap fromList (otoList x `stripPrefix` otoList y) - isPrefixOf :: seq -> seq -> Bool- isPrefixOf x y = otoList x `isPrefixOf` otoList y- stripSuffix :: seq -> seq -> Maybe seq stripSuffix x y = fmap fromList (otoList x `stripSuffix` otoList y) + isPrefixOf :: seq -> seq -> Bool+ isPrefixOf x y = otoList x `isPrefixOf` otoList y+ isSuffixOf :: seq -> seq -> Bool isSuffixOf x y = otoList x `isSuffixOf` otoList y @@ -968,120 +968,104 @@ -- not just the consecutive items. groupAll :: seq -> [seq] groupAll = groupAllOn id-- elem :: Element seq -> seq -> Bool- elem e = List.elem e . otoList-- notElem :: Element seq -> seq -> Bool- notElem e = List.notElem e . otoList- {-# INLINE stripPrefix #-} {-# INLINE isPrefixOf #-}- {-# INLINE stripSuffix #-} {-# INLINE isSuffixOf #-} {-# INLINE isInfixOf #-}+ {-# INLINE stripPrefix #-}+ {-# INLINE stripSuffix #-} {-# INLINE group #-} {-# INLINE groupAll #-}- {-# INLINE elem #-}- {-# INLINE notElem #-} +{-# DEPRECATED elem "use oelem" #-}+elem :: EqSequence seq => Element seq -> seq -> Bool+elem = oelem++{-# DEPRECATED notElem "use onotElem" #-}+notElem :: EqSequence seq => Element seq -> seq -> Bool+notElem = onotElem+ instance Eq a => EqSequence [a] where stripPrefix = List.stripPrefix- isPrefixOf = List.isPrefixOf stripSuffix x y = fmap reverse (List.stripPrefix (reverse x) (reverse y))- isSuffixOf x y = List.isPrefixOf (reverse x) (reverse y)- isInfixOf = List.isInfixOf group = List.group- elem = List.elem- notElem = List.notElem+ isPrefixOf = List.isPrefixOf+ isSuffixOf x y = List.isPrefixOf (List.reverse x) (List.reverse y)+ isInfixOf = List.isInfixOf {-# INLINE stripPrefix #-}- {-# INLINE isPrefixOf #-} {-# INLINE stripSuffix #-}- {-# INLINE isSuffixOf #-}- {-# INLINE isInfixOf #-} {-# INLINE group #-} {-# INLINE groupAll #-}- {-# INLINE elem #-}- {-# INLINE notElem #-}+ {-# INLINE isPrefixOf #-}+ {-# INLINE isSuffixOf #-}+ {-# INLINE isInfixOf #-} instance EqSequence S.ByteString where stripPrefix x y | x `S.isPrefixOf` y = Just (S.drop (S.length x) y) | otherwise = Nothing- isPrefixOf = S.isPrefixOf stripSuffix x y | x `S.isSuffixOf` y = Just (S.take (S.length y - S.length x) y) | otherwise = Nothing+ group = S.group+ isPrefixOf = S.isPrefixOf isSuffixOf = S.isSuffixOf isInfixOf = S.isInfixOf- group = S.group- elem = S.elem- notElem = S.notElem {-# INLINE stripPrefix #-}- {-# INLINE isPrefixOf #-} {-# INLINE stripSuffix #-}- {-# INLINE isSuffixOf #-}- {-# INLINE isInfixOf #-} {-# INLINE group #-} {-# INLINE groupAll #-}- {-# INLINE elem #-}- {-# INLINE notElem #-}+ {-# INLINE isPrefixOf #-}+ {-# INLINE isSuffixOf #-}+ {-# INLINE isInfixOf #-} instance EqSequence L.ByteString where stripPrefix x y | x `L.isPrefixOf` y = Just (L.drop (L.length x) y) | otherwise = Nothing- isPrefixOf = L.isPrefixOf stripSuffix x y | x `L.isSuffixOf` y = Just (L.take (L.length y - L.length x) y) | otherwise = Nothing+ group = L.group+ isPrefixOf = L.isPrefixOf isSuffixOf = L.isSuffixOf isInfixOf x y = L.unpack x `List.isInfixOf` L.unpack y- group = L.group- elem = L.elem- notElem = L.notElem {-# INLINE stripPrefix #-}- {-# INLINE isPrefixOf #-} {-# INLINE stripSuffix #-}- {-# INLINE isSuffixOf #-}- {-# INLINE isInfixOf #-} {-# INLINE group #-} {-# INLINE groupAll #-}- {-# INLINE elem #-}- {-# INLINE notElem #-}+ {-# INLINE isPrefixOf #-}+ {-# INLINE isSuffixOf #-}+ {-# INLINE isInfixOf #-} instance EqSequence T.Text where stripPrefix = T.stripPrefix- isPrefixOf = T.isPrefixOf stripSuffix = T.stripSuffix+ group = T.group+ isPrefixOf = T.isPrefixOf isSuffixOf = T.isSuffixOf isInfixOf = T.isInfixOf- group = T.group {-# INLINE stripPrefix #-}- {-# INLINE isPrefixOf #-} {-# INLINE stripSuffix #-}- {-# INLINE isSuffixOf #-}- {-# INLINE isInfixOf #-} {-# INLINE group #-} {-# INLINE groupAll #-}- {-# INLINE elem #-}- {-# INLINE notElem #-}+ {-# INLINE isPrefixOf #-}+ {-# INLINE isSuffixOf #-}+ {-# INLINE isInfixOf #-} instance EqSequence TL.Text where stripPrefix = TL.stripPrefix- isPrefixOf = TL.isPrefixOf stripSuffix = TL.stripSuffix+ group = TL.group+ isPrefixOf = TL.isPrefixOf isSuffixOf = TL.isSuffixOf isInfixOf = TL.isInfixOf- group = TL.group {-# INLINE stripPrefix #-}- {-# INLINE isPrefixOf #-} {-# INLINE stripSuffix #-}- {-# INLINE isSuffixOf #-}- {-# INLINE isInfixOf #-} {-# INLINE group #-} {-# INLINE groupAll #-}- {-# INLINE elem #-}- {-# INLINE notElem #-}+ {-# INLINE isPrefixOf #-}+ {-# INLINE isSuffixOf #-}+ {-# INLINE isInfixOf #-} instance Eq a => EqSequence (Seq.Seq a) instance Eq a => EqSequence (V.Vector a)