{-# LANGUAGE UnicodeSyntax #-}

-- | Provides a couple of convenience functions to be used for forming predicates. 
module Data.Function.Predicate
(is,isn't,equals)
where

-- |An example will explain this more than anything:
--
-- > listsLongerThan3Elements :: [[a]] -> [[a]]
-- > listsLongerThan3Elements = filter (length `is` (>3))
is :: (a  b)  (b  Bool)  (a  Bool)
is = flip (.)

-- |The inverse of 'is'.
--
-- > listsShorterThanFourElements = filter (length `isn't` (>3))
isn't :: (a  b)  (b  Bool)  (a  Bool)
isn't p x y = not $ (p `is` x) y

-- |This is 'is' with a fixed equality condition.
--
-- Example:
-- 
-- > data Color = White | Black deriving (Eq)
-- > data ChessPiece = { color :: Color, name :: String }
-- > whitePieces = filter (color `equals` White)
equals :: (Eq b)  (a  b)  b  a  Bool
equals p y x = p x == y