packages feed

filtrable 0.1.4.0 → 0.1.5.0

raw patch · 3 files changed

+58/−6 lines, 3 filesdep +filtrabledep +smallcheckdep +tastyPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: filtrable, smallcheck, tasty, tasty-smallcheck

API changes (from Hackage documentation)

- Data.Set.Private: Bin :: {-# UNPACK #-} !Size -> !a -> !Set a -> !Set a -> Set a
- Data.Set.Private: Tip :: Set a
- Data.Set.Private: data Set a
- Data.Set.Private: empty :: Set a
- Data.Set.Private: insertBy' :: (a -> a -> Ordering) -> a -> Set a -> Maybe (Set a)
- Data.Set.Private: type Size = Int
+ Data.Filtrable: instance Data.Filtrable.Filtrable f => Data.Filtrable.Filtrable (Control.Applicative.Backwards.Backwards f)
+ Data.Filtrable: instance Data.Filtrable.Filtrable f => Data.Filtrable.Filtrable (Data.Functor.Reverse.Reverse f)

Files

Data/Filtrable.hs view
@@ -7,11 +7,13 @@ import Prelude hiding (filter)  import Control.Applicative+import Control.Applicative.Backwards import Control.Monad import qualified Control.Monad.Trans.State as M import Data.Bool (bool) import Data.Functor.Compose import Data.Functor.Product+import Data.Functor.Reverse import Data.Functor.Sum import Data.Proxy import Data.Traversable@@ -92,12 +94,19 @@     mapMaybe f (Pair as bs) = Pair (mapMaybe f as) (mapMaybe f bs)  instance (Filtrable f, Filtrable g) => Filtrable (Sum f g) where-    mapMaybe f (InL as) = InL (mapMaybe f as)-    mapMaybe f (InR bs) = InR (mapMaybe f bs)+    mapMaybe f = \ case+        InL as -> InL (mapMaybe f as)+        InR bs -> InR (mapMaybe f bs)  instance (Functor f, Filtrable g) => Filtrable (Compose f g) where-    mapMaybe f (Compose as) = Compose (mapMaybe f <$> as)+    mapMaybe f = Compose . (fmap . mapMaybe) f . getCompose +instance Filtrable f => Filtrable (Backwards f) where+    mapMaybe f = Backwards . mapMaybe f . forwards++instance Filtrable f => Filtrable (Reverse f) where+    mapMaybe f = Reverse . mapMaybe f . getReverse+ infixl 4 <$?>, <*?>  (<$?>) :: Filtrable f => (a -> Maybe b) -> f a -> f b@@ -119,12 +128,12 @@     let b = all (not . eq a) as     b <$ when b (M.modify (a:)) --- | \(\mathcal{O}(n^2)\)+-- | \(\mathcal{O}(n\;\mathrm{log}\;n)\) -- Delete all but the first copy of each element, special case of 'nubOrdBy'. nubOrd :: (Filtrable f, Traversable f, Ord a) => f a -> f a nubOrd = nubOrdBy compare --- | \(\mathcal{O}(n^2)\)+-- | \(\mathcal{O}(n\;\mathrm{log}\;n)\) -- Delete all but the first copy of each element, with the given relation. nubOrdBy :: (Filtrable f, Traversable f) => (a -> a -> Ordering) -> f a -> f a nubOrdBy compare = fmap (flip M.evalState Set.empty) . filterA $ \ a -> M.state $ \ as ->
filtrable.cabal view
@@ -1,5 +1,5 @@ name:                filtrable-version:             0.1.4.0+version:             0.1.5.0 synopsis:            Class of filtrable containers homepage:            https://github.com/strake/filtrable.hs license:             BSD3@@ -34,3 +34,14 @@                        -Werror=incomplete-record-updates                        -Werror=missing-fields                        -Werror=missing-methods++test-suite test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  default-language:    Haskell2010+  build-depends:       base >=4.9 && <5+                     , filtrable+                     , smallcheck >=1.2 && <1.3+                     , tasty >=1.3.1 && <1.4+                     , tasty-smallcheck >=0.8.1 && <0.9
+ test/Spec.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE PartialTypeSignatures #-}++module Main (main) where++import Prelude hiding (filter)+import Control.Applicative+import Data.Foldable+import Data.Filtrable+import qualified Data.List as List+import Test.SmallCheck+import Test.Tasty+import Test.Tasty.SmallCheck++main :: IO ()+main = defaultMain $ testGroup ""+  [ testGroup "Filtrable"+      [ testProperty "filter" (prop_filter :: _ -> [Maybe Bool] -> _)+      ]+  , testGroup "nub"+      [ testProperty "nub" (prop_nub :: [Int] -> _)+      , testProperty "nubOrd" (prop_nubOrd :: [Int] -> _)+      ] +  ]++prop_filter :: (Filtrable f, Foldable f) => (a -> Bool) -> f a -> Bool+prop_filter = liftA2 (.) all filter++prop_nub :: (Filtrable f, Traversable f, Eq a) => f a -> Bool+prop_nub = (==) <$> List.nub . toList <*> toList . nub++prop_nubOrd :: (Filtrable f, Traversable f, Ord a) => f a -> Bool+prop_nubOrd = (==) <$> List.nub . toList <*> toList . nubOrd