module Cohort.Criteria
( Criterion(..)
, Status(..)
, Criteria
, firstExclude
, includeIf
, excludeIf
) where
import Control.Applicative (asum)
import qualified Data.List.NonEmpty as NE
import Data.Text (Text)
data Status = Include | Exclude deriving (Status -> Status -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Status -> Status -> Bool
$c/= :: Status -> Status -> Bool
== :: Status -> Status -> Bool
$c== :: Status -> Status -> Bool
Eq, Int -> Status -> ShowS
[Status] -> ShowS
Status -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Status] -> ShowS
$cshowList :: [Status] -> ShowS
show :: Status -> String
$cshow :: Status -> String
showsPrec :: Int -> Status -> ShowS
$cshowsPrec :: Int -> Status -> ShowS
Show)
data Criterion
= MkCriterion
{ Criterion -> Text
statusLabel :: Text
, Criterion -> Status
status :: Status
}
deriving (Criterion -> Criterion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Criterion -> Criterion -> Bool
$c/= :: Criterion -> Criterion -> Bool
== :: Criterion -> Criterion -> Bool
$c== :: Criterion -> Criterion -> Bool
Eq, Int -> Criterion -> ShowS
[Criterion] -> ShowS
Criterion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Criterion] -> ShowS
$cshowList :: [Criterion] -> ShowS
show :: Criterion -> String
$cshow :: Criterion -> String
showsPrec :: Int -> Criterion -> ShowS
$cshowsPrec :: Int -> Criterion -> ShowS
Show)
type Criteria = NE.NonEmpty Criterion
includeIf, excludeIf :: Bool -> Status
includeIf :: Bool -> Status
includeIf Bool
True = Status
Include
includeIf Bool
False = Status
Exclude
excludeIf :: Bool -> Status
excludeIf Bool
True = Status
Exclude
excludeIf Bool
False = Status
Include
firstExclude :: Criteria -> Maybe Criterion
firstExclude :: Criteria -> Maybe Criterion
firstExclude = forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map Criterion -> Maybe Criterion
op
where op :: Criterion -> Maybe Criterion
op (MkCriterion Text
lab Status
Exclude) = forall a. a -> Maybe a
Just (Text -> Status -> Criterion
MkCriterion Text
lab Status
Exclude)
op Criterion
_ = forall a. Maybe a
Nothing