-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Utilities for filtering -- -- Some helpers to make using Prelude.filter and similar value selection -- a bit easier. Includes combinators for predicates as well as an -- operator to match the constructor used for the given value. @package data-filter @version 0.1.0.0 -- | Some helpers to make using Prelude.filter and similar value selection -- a bit easier. Includes combinators for predicates as well as an -- operator to match the constructor used for the given value. module Data.Filter -- | Retrieve the constructor name of the given value as a string. This -- implementation is taken from -- https://stackoverflow.com/questions/48179380/getting-the-data-constructor-name-as-a-string-using-ghc-generics -- . constrName :: (HasConstructor (Rep a), Generic a) => a -> String -- | Automatically derived from Generic instances. class HasConstructor (f :: * -> *) genericConstrName :: HasConstructor f => f x -> String -- | Type that can be reduced away from a constructor. Use this to make -- your data types compatible. The reduction process and the -- (=?=)-operator do not evaluate fields, therefore creating an -- empty instance which defaults to reduceWith = -- undefined is okay as long as no reduced field of -- this type is strict. class ReduceWith a where reduceWith = undefined reduceWith :: ReduceWith a => a -- | Reduction of a constructor a -> ... -> c to a value of -- type c. class (HasConstructor (Rep c), Generic c) => Reduce a c | a -> c reduce :: Reduce a c => a -> c -- | Checks whether two values are created by the same data constructor. -- Also works with constructors that have not yet received all their -- arguments. This allows for very convenient constructs, e.g.: -- --
--   >>> Just 1 =?= Just
--   True
--   
-- --
--   >>> Just 1 =?= Nothing
--   False
--   
-- --
--   >>> let filterJust = filter (=?= Just)
--   
--   >>> filterJust [Just 1, Nothing, Just 9001]
--   [Just 1, Just 9001]
--   
-- --
--   >>> let filterJust_ = mapMaybe $ (=?= Just) ==> fromJust
--   
--   >>> filterJust_ [Just 1, Nothing, Just 9001]
--   [1, 9001]
--   
-- --
--   >>> let over9000 = mapMaybe $ ((=?= Just) <&&> (>9000) . fromJust) ==> fromJust
--   
--   >>> over9000 [Just 1, Nothing, Just 9001]
--   [9001]
--   
(=?=) :: (Reduce a c, Reduce b c) => a -> b -> Bool infixl 4 =?= -- | (pred ==> f) x returns Just (f x) if -- pred x succeeds and Nothing otherwise. (==>) :: (a -> Bool) -> (a -> b) -> a -> Maybe b (<||>) :: (a -> Bool) -> (a -> Bool) -> a -> Bool infixl 2 <||> any_ :: [a -> Bool] -> a -> Bool (<&&>) :: (a -> Bool) -> (a -> Bool) -> a -> Bool infixl 3 <&&> all_ :: [a -> Bool] -> a -> Bool -- | Adds negative and positive infinity to an ordered type. The -- fromEnum function is inherently susceptible to overflow since -- the class Enum is defined using Int instead of -- Integer, but this should not cause trouble with "small" enums. data Infinite a NegInfin :: Infinite a Exact :: !a -> Infinite a PosInfin :: Infinite a -- | The mapMaybe function is a version of map which can -- throw out elements. In particular, the functional argument returns -- something of type Maybe b. If this is Nothing, -- no element is added on to the result list. If it is Just -- b, then b is included in the result list. -- --

Examples

-- -- Using mapMaybe f x is a shortcut for -- catMaybes $ map f x in most cases: -- --
--   >>> import Text.Read ( readMaybe )
--   
--   >>> let readMaybeInt = readMaybe :: String -> Maybe Int
--   
--   >>> mapMaybe readMaybeInt ["1", "Foo", "3"]
--   [1,3]
--   
--   >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"]
--   [1,3]
--   
-- -- If we map the Just constructor, the entire list should be -- returned: -- --
--   >>> mapMaybe Just [1,2,3]
--   [1,2,3]
--   
mapMaybe :: (a -> Maybe b) -> [a] -> [b] instance GHC.Generics.Generic (Data.Filter.Infinite a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Filter.Infinite a) instance GHC.Show.Show a => GHC.Show.Show (Data.Filter.Infinite a) instance GHC.Read.Read a => GHC.Read.Read (Data.Filter.Infinite a) instance GHC.Base.Functor Data.Filter.Infinite instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Filter.Infinite a) instance Data.Filter.HasConstructor f => Data.Filter.HasConstructor (GHC.Generics.D1 c f) instance (Data.Filter.HasConstructor x, Data.Filter.HasConstructor y) => Data.Filter.HasConstructor (x GHC.Generics.:+: y) instance GHC.Generics.Constructor c => Data.Filter.HasConstructor (GHC.Generics.C1 c f) instance Data.Filter.ReduceWith GHC.Types.Bool instance Data.Filter.ReduceWith GHC.Types.Char instance Data.Default.Class.Default a => Data.Filter.ReduceWith a instance (Data.Filter.HasConstructor (GHC.Generics.Rep a), GHC.Generics.Generic a) => Data.Filter.Reduce a a instance (Data.Filter.ReduceWith a, Data.Filter.Reduce b c) => Data.Filter.Reduce (a -> b) c instance (GHC.Classes.Eq a, GHC.Enum.Bounded a, GHC.Enum.Enum a) => GHC.Enum.Enum (Data.Filter.Infinite a) instance Data.Default.Class.Default a => Data.Default.Class.Default (Data.Filter.Infinite a)