packages feed

predicate-transformers 0.1.0.0 → 0.2.0.0

raw patch · 2 files changed

+17/−3 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ PredicateTransformers: (!) :: (b -> a) -> (a -> c) -> b -> c
+ PredicateTransformers: allTrue :: [Pred a] -> Pred a
+ PredicateTransformers: eitherWay :: Pred a -> Pred b -> Pred (Either a b)
+ PredicateTransformers: pair :: Pred a -> Pred b -> Pred (a, b)

Files

predicate-transformers.cabal view
@@ -1,7 +1,7 @@ cabal-version:       2.4  name:                predicate-transformers-version:             0.1.0.0+version:             0.2.0.0 synopsis:            A library for writing predicates and transformations over predicates in Haskell description:   This package provides ways to write predicates such that they compose nicely and are easy to debug.
src/PredicateTransformers.hs view
@@ -5,7 +5,6 @@ -- and there are utilities for using predicate transformers with (`lens`-style) optics. module PredicateTransformers where -import Prelude hiding (all) import Control.Lens hiding (index, zoom) import Data.Foldable(toList) import Data.Functor.Rep(Representable(..))@@ -63,6 +62,10 @@ only p [x] = p x only _ _ = False +-- |Test all predicates against one value.+allTrue :: [Pred a] -> Pred a+allTrue ps a = all ($ a) ps+ -- |Given a list of predicates and a list of values, ensure that each predicate holds for each respective value. -- Fails if the two lists have different lengths. dist :: [Pred a] -> Pred [a]@@ -90,6 +93,17 @@ (==>) :: a -> b -> (a, b) (==>) = (,) +pair :: Pred a -> Pred b -> Pred (a,b)+pair f s (a,b) = f a && s b++eitherWay :: Pred a -> Pred b -> Pred (Either a b)+eitherWay f _ (Left a) = f a+eitherWay _ g (Right b) = g b++-- |Flipped function composition, meant to be used postfix.+(!) :: (b -> a) -> (a -> c) -> b -> c+(!) = flip (.)+ -- |Prints the input of a predicate, for debugging. traced :: Show a => PT a a-traced = function traceShowId+traced p a = traceShow a (p a)