Safe Haskell | None |
---|---|
Language | Haskell2010 |
- boolean expressions
- regex expressions
- tuple expressions
- character expressions
- datetime expressions
- numeric expressions
- proxy expressions
- read / show expressions
- aeson expressions
- arrow expressions
- compare expressions
- enum expressions
- wrap / unwrap expressions
- list / foldable expressions
- maybe expressions
- either expressions
- semigroup / monoid expressions
- indexing expressions
- cons / uncons expressions
- these expressions
- fold / unfold expressions
- failure expressions
- zip expressions
- conditional expressions
- IO expressions
- string expressions
- print expressions
- higher order expressions
- expression combinators
- miscellaneous
- tuples
Dsl for evaluating and displaying type level expressions
Contains instances of the class P
for evaluating expressions at the type level.
Synopsis
- data p && q
- data p &&~ q
- data p || q
- data p ||~ q
- data p ~> q
- data Not p
- data Ands p
- data Ors p
- data Asc
- data Asc'
- data Desc
- data Desc'
- data Between p q r
- data BetweenA p q
- data p <..> q
- data All p q
- data Any p q
- data AllPositive
- type Positive = Gt 0
- data AllNegative
- type Negative = Lt 0
- data AndA p q r
- data p &* q
- data OrA p q r
- data p |+ q
- data IdBool p
- data Re p q
- data Re' (rs :: [ROpt]) p q
- data Rescan p q
- data Rescan' (rs :: [ROpt]) p q
- data RescanRanges p q
- data RescanRanges' (rs :: [ROpt]) p q
- data Resplit p q
- data Resplit' (rs :: [ROpt]) p q
- data ReplaceAll p q r
- data ReplaceAll' (rs :: [ROpt]) p q r
- data ReplaceOne p q r
- data ReplaceOne' (rs :: [ROpt]) p q r
- data ReplaceAllString o p q r
- data ReplaceAllString' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r
- data ReplaceOneString (o :: ReplaceFnSub) p q r
- data ReplaceOneString' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r
- data ReplaceFn (o :: ReplaceFnSub) p
- data ReplaceFn1 p
- data ReplaceFn2 p
- data ReplaceFn3 p
- data Fst p
- data Snd p
- data Thd p
- data L1 p
- data L2 p
- data L3 p
- data L4 p
- data L5 p
- data L6 p
- data Dup
- data Swap
- class Bifunctor p => SwapC p where
- swapC :: p a b -> p b a
- data Assoc
- data Unassoc
- data Pairs
- data IsLower
- data IsUpper
- data IsDigit
- data IsSpace
- data IsPunctuation
- data IsControl
- data IsHexDigit
- data IsOctDigit
- data IsSeparator
- data IsLatin1
- data IsLowerAll
- data IsUpperAll
- data IsDigitAll
- data IsSpaceAll
- data IsPunctuationAll
- data IsControlAll
- data IsHexDigitAll
- data IsOctDigitAll
- data IsSeparatorAll
- data IsLatin1All
- data FormatTimeP p q
- data ParseTimeP (t :: Type) p q
- data ParseTimeP' t p q
- data ParseTimes (t :: Type) p q
- data ParseTimes' t p q
- data MkDay p
- data MkDay' p q r
- data UnMkDay p
- data MkDayExtra p
- data MkDayExtra' p q r
- data ToWeekDate p
- data ToWeekYear p
- data ToDay p
- data ToTime p
- data MkTime p
- data MkTime' p q r
- data UnMkTime p
- data PosixToUTCTime p
- data UTCTimeToPosix p
- data p + q
- data p - q
- data p * q
- data p / q
- data Negate p
- data Abs p
- data Signum p
- data FromInteger (t :: Type) p
- data FromInteger' t n
- data FromIntegral (t :: Type) p
- data FromIntegral' t n
- data Truncate (t :: Type) p
- data Truncate' t p
- data Ceiling (t :: Type) p
- data Ceiling' t p
- data Floor (t :: Type) p
- data Floor' t p
- data Even
- data Odd
- data Div p q
- data Mod p q
- data DivMod p q
- data QuotRem p q
- data Quot p q
- data Rem p q
- data LogBase p q
- data p ^ q
- data p ** q
- data p % q
- data p -% q
- data ToRational p
- data FromRational (t :: Type) p
- data FromRational' t r
- data MkProxy
- data ProxyT (t :: Type)
- data ProxyT' t
- data Unproxy
- data ShowP p
- data ReadP (t :: Type) p
- data ReadP' t p
- data ReadQ (t :: Type) p
- data ReadQ' t p
- data ReadMaybe (t :: Type) p
- data ReadMaybe' t p
- data ReadBase (t :: Type) (n :: Nat) p
- data ReadBase' t (n :: Nat) p
- data ShowBase (n :: Nat) p
- data ParseJson' t p
- data ParseJson (t :: Type) p
- data EncodeJson p
- data EncodeJsonFile p q
- data ParseJsonFile' t p
- data ParseJsonFile (t :: Type) p
- data p &&& q
- data p *** q
- data First p
- data Second q
- data p ||| q
- data p +++ q
- data p > q
- data p >= q
- data p == q
- data p /= q
- data p <= q
- data p < q
- data p >~ q
- data p >=~ q
- data p ==~ q
- data p /=~ q
- data p <=~ q
- data p <~ q
- type Gt n = I > n
- type Ge n = I >= n
- type Same n = I == n
- type Le n = I <= n
- type Lt n = I < n
- type Ne n = I /= n
- data p ==! q
- type OrdP p q = p ==! q
- data OrdA' p q
- data OrdA p
- type OrdI p q = p ===~ q
- data p ===~ q
- data Cmp (o :: OrderingP) p q
- data CmpI (o :: OrderingP) p q
- data Succ p
- data Pred p
- data FromEnum p
- data ToEnum (t :: Type) p
- data ToEnum' t p
- data EnumFromTo p q
- data EnumFromThenTo p q r
- data SuccB p q
- data SuccB' q
- data PredB p q
- data PredB' q
- data ToEnumBDef (t :: Type) def
- data ToEnumBDef' t def
- data ToEnumBFail (t :: Type)
- data Unwrap p
- data Wrap (t :: Type) p
- data Wrap' t p
- data Coerce (t :: k)
- data Coerce2 (t :: k)
- data Map p q
- data Concat p
- data ConcatMap p q
- data Partition p q
- data GroupOn t p q
- data Filter p q
- data Break p q
- data Span p q
- data Intercalate p q
- data Elem p q
- data Inits
- data Tails
- data Ones p
- data OneP p
- data Len
- data Length p
- data PadL n p q
- data PadR n p q
- data Cycle n p
- data SplitAts ns p
- data SplitAt n p
- data ChunksOf n p
- data Rotate n p
- data Take n p
- data Drop n p
- data Min
- data Max
- data Sum
- data Product
- data IsEmpty
- data Null
- data Null' p
- data ToList
- data ToList' p
- data IToList (t :: Type) p
- data IToList' t p
- data FromList (t :: Type)
- data EmptyList (t :: Type)
- data EmptyList' t
- data Singleton p
- data Reverse
- data ReverseL
- data SortBy p q
- data SortOn p q
- data SortOnDesc p q
- data Remove p q
- data Keep p q
- data ToListExt
- data FromListExt (t :: Type)
- data MkNothing (t :: Type)
- data MkNothing' t
- data MkJust p
- data IsNothing p
- data IsJust p
- data MapMaybe p q
- data CatMaybes q
- data Just p
- data JustDef p q
- data JustFail p q
- data MaybeIn p q
- data MaybeBool b p
- data PartitionEithers
- data IsLeft p
- data IsRight p
- data MkLeft (t :: Type) p
- data MkLeft' t p
- data MkRight (t :: Type) p
- data MkRight' t p
- data Left' p
- data Right' p
- data LeftDef p q
- data LeftFail p q
- data RightDef p q
- data RightFail p q
- data EitherBool b p q
- type EitherIn p q = p ||| q
- data p <> q
- data MConcat p
- data STimes n p
- data SapA
- data SapA' (t :: Type)
- data MEmptyT (t :: Type)
- data MEmptyT' t
- data MEmptyP
- data MEmpty2 (t :: Type)
- data MEmpty2' t
- data Ix (n :: Nat) def
- data Ix' (n :: Nat)
- data IxL p q def
- data p !! q
- data p !!? q
- data Lookup p q
- data LookupDef v w p
- data LookupDef' v w p q
- data LookupFail msg v w
- data LookupFail' msg v w q
- data p :+ q
- data p +: q
- data p ++ q
- data Uncons
- data Unsnoc
- data Head p
- data Tail p
- data Init p
- data Last p
- data HeadDef p q
- data HeadFail msg q
- data TailDef p q
- data TailFail msg q
- data LastDef p q
- data LastFail msg q
- data InitDef p q
- data InitFail msg q
- data PartitionThese
- data Thiss
- data Thats
- data Theses
- data This' p
- data That' p
- data These' p
- data IsThis p
- data IsThat p
- data IsThese p
- data MkThis (t :: Type) p
- data MkThis' t p
- data MkThat (t :: Type) p
- data MkThat' t p
- data MkThese p q
- data ThisDef p q
- data ThisFail p q
- data ThatDef p q
- data ThatFail p q
- data TheseDef p q
- data TheseFail p q
- data TheseIn p q r
- data TheseId p q
- data TheseX p q r s
- data Scanl p q r
- data ScanN n p q
- data ScanNA q
- data FoldN n p q
- data FoldL p q r
- data Unfoldr p q
- data IterateN n f
- data IterateUntil p f
- data IterateWhile p f
- data IterateNWhile n p f
- data IterateNUntil n p f
- data Fail t prt
- data Failp p
- data Failt (t :: Type) p
- data FailS p
- data Catch p q
- data Catch' p s
- data ZipThese p q
- data ZipL l p q
- data ZipR r p q
- data Zip p q
- data Unzip
- data Unzip3
- data If p q r
- data Case (e :: k0) (ps :: [k]) (qs :: [k1]) (r :: k2)
- data Case' (ps :: [k]) (qs :: [k1]) (r :: k2)
- data Case'' s (ps :: [k]) (qs :: [k1]) (r :: k2)
- data Guards (ps :: [(k, k1)])
- data GuardsQuick (prt :: k) (ps :: [k1])
- data Guard prt p
- data ExitWhen prt p
- data GuardSimple p
- data GuardsN prt (n :: Nat) p
- data GuardsDetail prt (ps :: [(k0, k1)])
- data Bools (ps :: [(k, k1)])
- data BoolsQuick (prt :: k) (ps :: [k1])
- data BoolsN prt (n :: Nat) (p :: k1)
- data ReadFile p
- data FileExists p
- data ReadDir p
- data DirExists p
- data ReadEnv p
- data ReadEnvAll
- data TimeUtc
- data TimeZt
- data AppendFile (s :: Symbol) p
- data WriteFile (s :: Symbol) p
- data WriteFile' (s :: Symbol) p
- data Stdout p
- data Stderr p
- data Stdin
- type ReadIO (t :: Type) = ReadIO' t "Enter value"
- type ReadIO' (t :: Type) s = Stdout (s <> ":") >> (Stdin >> ReadP t Id)
- data ToLower
- data ToUpper
- data ToTitle
- data TrimBoth p
- data TrimL p
- data TrimR p
- data StripR p q
- data StripL p q
- data IsPrefix p q
- data IsInfix p q
- data IsSuffix p q
- data IsPrefixI p q
- data IsInfixI p q
- data IsSuffixI p q
- data ToString p
- data FromString (t :: Type) p
- data FromString' t s
- data PrintF s p
- data PrintL (n :: Nat) s p
- data PrintT s p
- data Pure (t :: Type -> Type) p
- data Pure2 (t :: Type -> Type)
- data FoldMap (t :: Type) p
- data p <$ q
- data p <* q
- data p *> q
- data FMapFst
- data FMapSnd
- data Sequence
- data Traverse p q
- data Join
- data EmptyT (t :: Type -> Type) p
- data p <|> q
- data Extract
- data Duplicate
- data (p :: k -> k1) $ (q :: k)
- data (q :: k) & (p :: k -> k1)
- data Do (ps :: [k])
- data Dot (ps :: [Type -> Type]) (q :: Type)
- data RDot (ps :: [Type -> Type]) (q :: Type)
- data p >> q
- data p << q
- type (>>>) p q = p >> q
- data DoN (n :: Nat) p
- data p $$ q
- data q $& p
- data K (p :: k) (q :: k1)
- data Hide p
- data Hole (t :: Type)
- data Skip p
- data p |> q
- data p >| q
- data p >|> q
- data Uncurry (p :: Type -> Type -> Type -> Type) q r
- data Para (ps :: [k])
- data ParaN (n :: Nat) p
- data Repeat (n :: Nat) p
- data Both p q
- data Prime p
- data PrimeNext p
- data Luhn p
- data Char1 (s :: Symbol)
- type Tuple2 p = '(p !! 0, p !! 1)
- type Tuple3 p = '(p !! 0, p !! 1, p !! 2)
- type Tuple4 p = '(p !! 0, p !! 1, p !! 2, p !! 3)
- type Tuple5 p = '(p !! 0, p !! 1, p !! 2, p !! 3, p !! 4)
- type Tuple6 p = '(p !! 0, p !! 1, p !! 2, p !! 3, p !! 4, p !! 5)
boolean expressions
similar to &&
>>>
pz @(Fst Id && Snd Id) (True, True)
TrueT
>>>
pz @(Id > 15 && Id < 17) 16
TrueT
>>>
pz @(Id > 15 && Id < 17) 30
FalseT
>>>
pz @(Fst Id && (Length (Snd Id) >= 4)) (True,[11,12,13,14])
TrueT
>>>
pz @(Fst Id && (Length (Snd Id) == 4)) (True,[12,11,12,13,14])
FalseT
data p &&~ q infixr 3 Source #
short circuit version of boolean And
>>>
pl @(Id > 10 &&~ Failt _ "ss") 9
False (False &&~ ... | (9 > 10)) FalseT
>>>
pl @(Id > 10 &&~ Id == 12) 11
False (True &&~ False | (11 == 12)) FalseT
>>>
pl @(Id > 10 &&~ Id == 11) 11
True (True &&~ True) TrueT
similar to ||
>>>
pz @(Fst Id || (Length (Snd Id) >= 4)) (False,[11,12,13,14])
TrueT
>>>
pz @(Not (Fst Id) || (Length (Snd Id) == 4)) (True,[12,11,12,13,14])
FalseT
data p ||~ q infixr 2 Source #
short circuit version of boolean Or
>>>
pl @(Id > 10 ||~ Failt _ "ss") 11
True (True ||~ ...) TrueT
>>>
pz @(Id > 10 ||~ Id == 9) 9
TrueT
>>>
pl @(Id > 10 ||~ Id > 9) 9
False (False ||~ False | (9 > 10) ||~ (9 > 9)) FalseT
implication
>>>
pz @(Fst Id ~> (Length (Snd Id) >= 4)) (True,[11,12,13,14])
TrueT
>>>
pz @(Fst Id ~> (Length (Snd Id) == 4)) (True,[12,11,12,13,14])
FalseT
>>>
pz @(Fst Id ~> (Length (Snd Id) == 4)) (False,[12,11,12,13,14])
TrueT
>>>
pz @(Fst Id ~> (Length (Snd Id) >= 4)) (False,[11,12,13,14])
TrueT
not
function
>>>
pz @(Not Id) False
TrueT
>>>
pz @(Not Id) True
FalseT
>>>
pz @(Not (Fst Id)) (True,22)
FalseT
>>>
pl @(Not (Lt 3)) 13
True (Not (13 < 3)) TrueT
>>>
pz @(Ands Id) [True,True,True]
TrueT
>>>
pl @(Ands Id) [True,True,True,False]
False (Ands(4) i=3 | [True,True,True,False]) FalseT
>>>
pz @(Ands Id) []
TrueT
>>>
pz @(Ors Id) [False,False,False]
FalseT
>>>
pl @(Ors Id) [True,True,True,False]
True (Ors(4) i=0 | [True,True,True,False]) TrueT
>>>
pl @(Ors Id) []
False (Ors(0) | []) FalseT
a type level predicate for a monotonic increasing list
>>>
pl @Asc "aaacdef"
True (All(6)) TrueT
>>>
pz @Asc [1,2,3,4,5,5,7]
TrueT
>>>
pz @Asc' [1,2,3,4,5,5,7]
FalseT
>>>
pz @Asc "axacdef"
FalseT
a type level predicate for a monotonic increasing list
a type level predicate for a strictly increasing list
a type level predicate for a monotonic decreasing list
a type level predicate for a strictly decreasing list
A predicate that determines if the value is between 'p' and 'q'
>>>
pz @(Between 5 8 Len) [1,2,3,4,5,5,7]
TrueT
>>>
pz @(5 <..> 8) 6
TrueT
>>>
pl @(Between 5 8 Id) 9
False (9 <= 8) FalseT
>>>
pz @(10 % 4 <..> 40 % 5) 4
TrueT
>>>
pz @(10 % 4 <..> 40 % 5) 33
FalseT
between for tuples
>>>
pl @(BetweenA (Fst Id) (Snd Id)) ((1,4),8)
False (8 <= 4) FalseT
>>>
pl @(BetweenA (Fst Id) (Snd Id)) ((1,4),0)
False (1 <= 0) FalseT
>>>
pl @(BetweenA (Fst Id) (Snd Id)) ((1,4),3)
True (1 <= 3 <= 4) TrueT
>>>
pl @(BetweenA (ReadP (Day,Day) "(2017-04-11,2018-12-30)") (ReadP Day Id)) "2018-10-12"
True (2017-04-11 <= 2018-10-12 <= 2018-12-30) TrueT
>>>
pl @(BetweenA (ReadP (Day,Day) "(2017-04-11,2018-12-30)") (ReadP Day Id)) "2019-10-12"
False (2019-10-12 <= 2018-12-30) FalseT
>>>
pl @(BetweenA (ReadP (Day,Day) "(2017-04-11,2018-12-30)") (ReadP Day Id)) "2016-10-12"
False (2017-04-11 <= 2016-10-12) FalseT
similar to all
>>>
pl @(All (Between 1 8 Id) Id) [7,3,4,1,2,9,0,1]
False (All(8) i=5 (9 <= 8)) FalseT
>>>
pz @(All Odd Id) [1,5,11,5,3]
TrueT
>>>
pz @(All Odd Id) []
TrueT
>>>
pan @(All Even Id) [1,5,11,5,3]
False All(5) i=0 (1 == 0) | +- P Id [1,5,11,5,3] | +- False i=0:1 == 0 | | | +- P 1 `mod` 2 = 1 | | | | | +- P I | | | | | `- P '2 | | | `- P '0 | +- False i=1:1 == 0 | | | +- P 5 `mod` 2 = 1 | | | | | +- P I | | | | | `- P '2 | | | `- P '0 | +- False i=2:1 == 0 | | | +- P 11 `mod` 2 = 1 | | | | | +- P I | | | | | `- P '2 | | | `- P '0 | +- False i=3:1 == 0 | | | +- P 5 `mod` 2 = 1 | | | | | +- P I | | | | | `- P '2 | | | `- P '0 | `- False i=4:1 == 0 | +- P 3 `mod` 2 = 1 | | | +- P I | | | `- P '2 | `- P '0 FalseT
similar to any
>>>
pl @(Any Even Id) [1,5,11,5,3]
False (Any(5)) FalseT
>>>
pl @(Any Even Id) [1,5,112,5,3]
True (Any(5) i=2 (0 == 0)) TrueT
>>>
pz @(Any Even Id) []
FalseT
data AllPositive Source #
a type level predicate for all positive elements in a list
>>>
pz @AllPositive [1,5,10,2,3]
TrueT
>>>
pz @AllPositive [0,1,5,10,2,3]
FalseT
>>>
pz @AllPositive [3,1,-5,10,2,3]
FalseT
>>>
pz @AllNegative [-1,-5,-10,-2,-3]
TrueT
Instances
P AllPositiveT x => P AllPositive x Source # | |
Defined in Predicate.Prelude type PP AllPositive x :: Type Source # eval :: MonadEval m => Proxy AllPositive -> POpts -> x -> m (TT (PP AllPositive x)) Source # | |
type PP AllPositive x Source # | |
Defined in Predicate.Prelude |
data AllNegative Source #
a type level predicate for all negative elements in a list
Instances
P AllNegativeT x => P AllNegative x Source # | |
Defined in Predicate.Prelude type PP AllNegative x :: Type Source # eval :: MonadEval m => Proxy AllNegative -> POpts -> x -> m (TT (PP AllNegative x)) Source # | |
type PP AllNegative x Source # | |
Defined in Predicate.Prelude |
like &&
but for a tuple
>>>
pl @(SplitAt 4 "abcdefg" >> Len > 4 &* Len < 5) ()
False ((>>) False | {False (&*) True | (4 > 4)}) FalseT
like ||
but for a tuple
>>>
pl @(Sum > 44 |+ Id < 2) ([5,6,7,8,14,44],9)
True (True (|+) False) TrueT
>>>
pl @(Sum > 44 |+ Id < 2) ([5,6,7,14],9)
False (False (|+) False | (32 > 44) (|+) (9 < 2)) FalseT
>>>
pl @(Sum > 44 |+ Id < 2) ([5,6,7,14],1)
True (False (|+) True) TrueT
id
function on a boolean
>>>
pz @(IdBool Id) False
FalseT
>>>
pz @(IdBool Id) True
TrueT
>>>
pz @(IdBool (Fst Id)) (True,22)
TrueT
>>>
pl @(IdBool (Lt 3)) 13
False (IdBool (13 < 3)) FalseT
regex expressions
data Re' (rs :: [ROpt]) p q Source #
represents a predicate using a Symbol
as a regular expression
evaluates Re
and returns True if there is a match
>>>
pz @(Re "^\\d{2}:\\d{2}:\\d{2}$" Id) "13:05:25"
TrueT
data Rescan' (rs :: [ROpt]) p q Source #
runs a regex matcher returning the original values and optionally any groups
>>>
pz @(Rescan "^(\\d{2}):(\\d{2}):(\\d{2})$" Id) "13:05:25"
PresentT [("13:05:25",["13","05","25"])]
>>>
pz @(Rescan (Snd Id) "13:05:25") ('a',"^(\\d{2}):(\\d{2}):(\\d{2})$")
PresentT [("13:05:25",["13","05","25"])]
data RescanRanges p q Source #
Instances
P (RescanRangesT p q) x => P (RescanRanges p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (RescanRanges p q) x :: Type Source # eval :: MonadEval m => Proxy (RescanRanges p q) -> POpts -> x -> m (TT (PP (RescanRanges p q) x)) Source # | |
type PP (RescanRanges p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data RescanRanges' (rs :: [ROpt]) p q Source #
similar to Rescan
but gives the column start and ending positions instead of values
>>>
pz @(RescanRanges "^(\\d{2}):(\\d{2}):(\\d{2})$" Id) "13:05:25"
PresentT [((0,8),[(0,2),(3,5),(6,8)])]
Instances
(GetROpts rs, PP p x ~ String, PP q x ~ String, P p x, P q x) => P (RescanRanges' rs p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (RescanRanges' rs p q) x :: Type Source # eval :: MonadEval m => Proxy (RescanRanges' rs p q) -> POpts -> x -> m (TT (PP (RescanRanges' rs p q) x)) Source # | |
type PP (RescanRanges' rs p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data Resplit' (rs :: [ROpt]) p q Source #
splits a string on a regex delimiter
>>>
pz @(Resplit "\\." Id) "141.201.1.22"
PresentT ["141","201","1","22"]
>>>
pz @(Resplit (Singleton (Fst Id)) (Snd Id)) (':', "12:13:1")
PresentT ["12","13","1"]
>>>
pl @(Resplit' '[ 'Caseless ] "aBc" Id) "123AbC456abc"
Present ["123","456",""] (Resplit (aBc) ["123","456",""] | 123AbC456abc) PresentT ["123","456",""]
data ReplaceAll p q r Source #
Instances
P (ReplaceAllT p q r) x => P (ReplaceAll p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceAll p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceAll p q r) -> POpts -> x -> m (TT (PP (ReplaceAll p q r) x)) Source # | |
type PP (ReplaceAll p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceAll' (rs :: [ROpt]) p q r Source #
Instances
P (ReplaceAllT' rs p q r) x => P (ReplaceAll' rs p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceAll' rs p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceAll' rs p q r) -> POpts -> x -> m (TT (PP (ReplaceAll' rs p q r) x)) Source # | |
type PP (ReplaceAll' rs p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceOne p q r Source #
replace first occurrence of string 'p' with '\q' in 'r'
>>>
pl @(ReplaceOneString 'ROverWrite "abc" "def" Id) "123abc456abc"
Present "123def456abc" (ReplaceOne' [] (abc) 123abc456abc | 123def456abc) PresentT "123def456abc"
>>>
pz @(Rescan "^Date\\((\\d+[+-]\\d{4})\\)" Id >> Head Id >> Snd Id >> Id !! 0 >> ReplaceOneString 'RPrepend "\\d{3}[+-]" "." Id >> ParseTimeP ZonedTime "%s%Q%z" Id) "Date(1530144000123+0530)"
PresentT 2018-06-28 05:30:00.123 +0530
>>>
pz @(Rescan "^Date\\((\\d+[+-]\\d{4})\\)" Id >> Head Id >> Snd Id >> Id !! 0 >> ReplaceOneString 'RPrepend "\\d{3}[+-]" "." Id >> ParseTimeP ZonedTime "%s%Q%z" Id) "Date(1593460089052+0800)"
PresentT 2020-06-30 03:48:09.052 +0800
>>>
pz @(Rescan "^Date\\((\\d+)(\\d{3}[+-]\\d{4})\\)" Id >> Head Id >> Snd Id >> (Id !! 0 <> "." <> Id !! 1) >> ParseTimeP ZonedTime "%s%Q%z" Id) "Date(1593460089052+0800)"
PresentT 2020-06-30 03:48:09.052 +0800
Instances
P (ReplaceOneT p q r) x => P (ReplaceOne p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceOne p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceOne p q r) -> POpts -> x -> m (TT (PP (ReplaceOne p q r) x)) Source # | |
type PP (ReplaceOne p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceOne' (rs :: [ROpt]) p q r Source #
Instances
P (ReplaceOneT' rs p q r) x => P (ReplaceOne' rs p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceOne' rs p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceOne' rs p q r) -> POpts -> x -> m (TT (PP (ReplaceOne' rs p q r) x)) Source # | |
type PP (ReplaceOne' rs p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceAllString o p q r Source #
Instances
P (ReplaceAllStringT o p q r) x => P (ReplaceAllString o p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceAllString o p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceAllString o p q r) -> POpts -> x -> m (TT (PP (ReplaceAllString o p q r) x)) Source # | |
type PP (ReplaceAllString o p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceAllString' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r Source #
replace all occurrences of string 'p' with '\q' in 'r'
>>>
pl @(ReplaceAllString 'ROverWrite "abc" "def" Id) "123abc456abc"
Present "123def456def" (ReplaceAll' [] (abc) 123abc456abc | 123def456def) PresentT "123def456def"
>>>
pl @(ReplaceAllString' '[] 'ROverWrite "abc" "def" Id) "123AbC456abc"
Present "123AbC456def" (ReplaceAll' [] (abc) 123AbC456abc | 123AbC456def) PresentT "123AbC456def"
>>>
pl @(ReplaceAllString' '[ 'Caseless ] 'ROverWrite "abc" "def" Id) "123AbC456abc"
Present "123def456def" (ReplaceAll (abc) 123AbC456abc | 123def456def) PresentT "123def456def"
>>>
pl @(ReplaceAllString 'RPrepend "abc" "def" Id) "123AbC456abc"
Present "123AbC456defabc" (ReplaceAll' [] (abc) 123AbC456abc | 123AbC456defabc) PresentT "123AbC456defabc"
>>>
pl @(ReplaceAllString 'ROverWrite "abc" "def" Id) "123AbC456abc"
Present "123AbC456def" (ReplaceAll' [] (abc) 123AbC456abc | 123AbC456def) PresentT "123AbC456def"
>>>
pl @(ReplaceAllString 'RAppend "abc" "def" Id) "123AbC456abc"
Present "123AbC456abcdef" (ReplaceAll' [] (abc) 123AbC456abc | 123AbC456abcdef) PresentT "123AbC456abcdef"
Instances
P (ReplaceAllStringT' rs o p q r) x => P (ReplaceAllString' rs o p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceAllString' rs o p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceAllString' rs o p q r) -> POpts -> x -> m (TT (PP (ReplaceAllString' rs o p q r) x)) Source # | |
type PP (ReplaceAllString' rs o p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceOneString (o :: ReplaceFnSub) p q r Source #
Instances
P (ReplaceOneStringT o p q r) x => P (ReplaceOneString o p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceOneString o p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceOneString o p q r) -> POpts -> x -> m (TT (PP (ReplaceOneString o p q r) x)) Source # | |
type PP (ReplaceOneString o p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceOneString' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r Source #
Instances
P (ReplaceOneStringT' rs o p q r) x => P (ReplaceOneString' rs o p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceOneString' rs o p q r) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceOneString' rs o p q r) -> POpts -> x -> m (TT (PP (ReplaceOneString' rs o p q r) x)) Source # | |
type PP (ReplaceOneString' rs o p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceFn (o :: ReplaceFnSub) p Source #
Simple replacement string: see ReplaceAllString
and ReplaceOneString
data ReplaceFn1 p Source #
A replacement function (String -> [String] -> String)
which returns the whole match and the groups
Used by sub
and gsub
Requires Text.Show.Functions
Instances
(PP p x ~ (String -> [String] -> String), P p x) => P (ReplaceFn1 p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceFn1 p) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceFn1 p) -> POpts -> x -> m (TT (PP (ReplaceFn1 p) x)) Source # | |
type PP (ReplaceFn1 p :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceFn2 p Source #
A replacement function (String -> String)
that yields the whole match
Used by sub
and gsub
Requires Text.Show.Functions
>>>
:m + Text.Show.Functions
>>>
pz @(ReplaceAll "\\." (ReplaceFn2 (Fst Id)) (Snd Id)) (\x -> x <> ":" <> x, "141.201.1.22")
PresentT "141.:.201.:.1.:.22"
Instances
(PP p x ~ (String -> String), P p x) => P (ReplaceFn2 p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceFn2 p) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceFn2 p) -> POpts -> x -> m (TT (PP (ReplaceFn2 p) x)) Source # | |
type PP (ReplaceFn2 p :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReplaceFn3 p Source #
A replacement function ([String] -> String)
which yields the groups
Used by sub
and gsub
Requires Text.Show.Functions
>>>
:m + Text.Show.Functions
>>>
pz @(ReplaceAll "^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$" (ReplaceFn3 (Fst Id)) (Snd Id)) (\ys -> intercalate " | " $ map (show . succ . readNote @Int "invalid int") ys, "141.201.1.22")
PresentT "142 | 202 | 2 | 23"
Instances
(PP p x ~ ([String] -> String), P p x) => P (ReplaceFn3 p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReplaceFn3 p) x :: Type Source # eval :: MonadEval m => Proxy (ReplaceFn3 p) -> POpts -> x -> m (TT (PP (ReplaceFn3 p) x)) Source # | |
type PP (ReplaceFn3 p :: Type) x Source # | |
Defined in Predicate.Prelude |
tuple expressions
similar to fst
>>>
pz @(Fst Id) (10,"Abc")
PresentT 10
>>>
pz @(Fst Id) (10,"Abc",'x')
PresentT 10
>>>
pz @(Fst Id) (10,"Abc",'x',False)
PresentT 10
similar to snd
>>>
pz @(Snd Id) (10,"Abc")
PresentT "Abc"
>>>
pz @(Snd Id) (10,"Abc",True)
PresentT "Abc"
similar to 3rd element in a n-tuple
>>>
pz @(Thd Id) (10,"Abc",133)
PresentT 133
>>>
pz @(Thd Id) (10,"Abc",133,True)
PresentT 133
similar to 4th element in a n-tuple
>>>
pz @(L4 Id) (10,"Abc",'x',True)
PresentT True
>>>
pz @(L4 (Fst (Snd Id))) ('x',((10,"Abc",'x',999),"aa",1),9)
PresentT 999
similar to 5th element in a n-tuple
>>>
pz @(L5 Id) (10,"Abc",'x',True,1)
PresentT 1
similar to 6th element in a n-tuple
>>>
pz @(L6 Id) (10,"Abc",'x',True,1,99)
PresentT 99
swaps using SwapC
>>>
pz @Swap (Left 123)
PresentT (Right 123)
>>>
pz @Swap (Right 123)
PresentT (Left 123)
>>>
pz @Swap (These 'x' 123)
PresentT (These 123 'x')
>>>
pz @Swap (This 'x')
PresentT (That 'x')
>>>
pz @Swap (That 123)
PresentT (This 123)
>>>
pz @Swap (123,'x')
PresentT ('x',123)
>>>
pz @Swap (Left "abc")
PresentT (Right "abc")
>>>
pz @Swap (Right 123)
PresentT (Left 123)
assoc using AssocC
>>>
pz @Assoc (This (These 123 'x'))
PresentT (These 123 (This 'x'))
>>>
pz @Assoc ((99,'a'),True)
PresentT (99,('a',True))
>>>
pz @Assoc ((99,'a'),True)
PresentT (99,('a',True))
>>>
pz @Assoc (Right "Abc" :: Either (Either () ()) String)
PresentT (Right (Right "Abc"))
>>>
pz @Assoc (Left (Left 'x'))
PresentT (Left 'x')
unassoc using AssocC
>>>
pz @Unassoc (These 123 (This 'x'))
PresentT (This (These 123 'x'))
>>>
pz @Unassoc (99,('a',True))
PresentT ((99,'a'),True)
>>>
pz @Unassoc (This 10 :: These Int (These Bool ()))
PresentT (This (This 10))
>>>
pz @Unassoc (Right (Right 123))
PresentT (Right 123)
>>>
pz @Unassoc (Left 'x' :: Either Char (Either Bool Double))
PresentT (Left (Left 'x'))
creates a list of overlapping pairs of elements. requires two or more elements
>>>
pz @Pairs [1,2,3,4]
PresentT [(1,2),(2,3),(3,4)]
>>>
pz @Pairs []
FailT "Pairs no data found"
>>>
pz @Pairs [1]
FailT "Pairs only one element found"
character expressions
predicate for determining if a character is lowercase
>>>
pz @IsLower '1'
FalseT
>>>
pz @IsLower 'a'
TrueT
>>>
pz @(Map '(IsControl, IsLatin1, IsHexDigit, IsOctDigit, IsDigit, IsPunctuation, IsSeparator, IsSpace) Id) "abc134"
PresentT [(False,True,True,False,False,False,False,False),(False,True,True,False,False,False,False,False),(False,True,True,False,False,False,False,False),(False,True,True,True,True,False,False,False),(False,True,True,True,True,False,False,False),(False,True,True,True,True,False,False,False)]
predicate for determining if the character is a digit
>>>
pz @IsDigit 'g'
FalseT
>>>
pz @IsDigit '9'
TrueT
data IsPunctuation Source #
Instances
P IsPunctuationT x => P IsPunctuation x Source # | |
Defined in Predicate.Prelude type PP IsPunctuation x :: Type Source # eval :: MonadEval m => Proxy IsPunctuation -> POpts -> x -> m (TT (PP IsPunctuation x)) Source # | |
type PP IsPunctuation x Source # | |
Defined in Predicate.Prelude |
data IsHexDigit Source #
Instances
P IsHexDigitT x => P IsHexDigit x Source # | |
Defined in Predicate.Prelude type PP IsHexDigit x :: Type Source # eval :: MonadEval m => Proxy IsHexDigit -> POpts -> x -> m (TT (PP IsHexDigit x)) Source # | |
type PP IsHexDigit x Source # | |
Defined in Predicate.Prelude |
data IsOctDigit Source #
Instances
P IsOctDigitT x => P IsOctDigit x Source # | |
Defined in Predicate.Prelude type PP IsOctDigit x :: Type Source # eval :: MonadEval m => Proxy IsOctDigit -> POpts -> x -> m (TT (PP IsOctDigit x)) Source # | |
type PP IsOctDigit x Source # | |
Defined in Predicate.Prelude |
data IsSeparator Source #
Instances
P IsSeparatorT x => P IsSeparator x Source # | |
Defined in Predicate.Prelude type PP IsSeparator x :: Type Source # eval :: MonadEval m => Proxy IsSeparator -> POpts -> x -> m (TT (PP IsSeparator x)) Source # | |
type PP IsSeparator x Source # | |
Defined in Predicate.Prelude |
data IsLowerAll Source #
Instances
P IsLowerAllT x => P IsLowerAll x Source # | |
Defined in Predicate.Prelude type PP IsLowerAll x :: Type Source # eval :: MonadEval m => Proxy IsLowerAll -> POpts -> x -> m (TT (PP IsLowerAll x)) Source # | |
type PP IsLowerAll x Source # | |
Defined in Predicate.Prelude |
data IsUpperAll Source #
Instances
P IsUpperAllT x => P IsUpperAll x Source # | |
Defined in Predicate.Prelude type PP IsUpperAll x :: Type Source # eval :: MonadEval m => Proxy IsUpperAll -> POpts -> x -> m (TT (PP IsUpperAll x)) Source # | |
type PP IsUpperAll x Source # | |
Defined in Predicate.Prelude |
data IsDigitAll Source #
predicate for determining if the string is all digits
>>>
pz @IsDigitAll "213G"
FalseT
>>>
pz @IsDigitAll "929"
TrueT
Instances
P IsDigitAllT x => P IsDigitAll x Source # | |
Defined in Predicate.Prelude type PP IsDigitAll x :: Type Source # eval :: MonadEval m => Proxy IsDigitAll -> POpts -> x -> m (TT (PP IsDigitAll x)) Source # | |
type PP IsDigitAll x Source # | |
Defined in Predicate.Prelude |
data IsSpaceAll Source #
predicate for determining if the string is all spaces
>>>
pz @IsSpaceAll "213G"
FalseT
>>>
pz @IsSpaceAll " "
TrueT
>>>
pz @IsSpaceAll ""
TrueT
Instances
P IsSpaceAllT x => P IsSpaceAll x Source # | |
Defined in Predicate.Prelude type PP IsSpaceAll x :: Type Source # eval :: MonadEval m => Proxy IsSpaceAll -> POpts -> x -> m (TT (PP IsSpaceAll x)) Source # | |
type PP IsSpaceAll x Source # | |
Defined in Predicate.Prelude |
data IsPunctuationAll Source #
Instances
P IsPunctuationAllT x => P IsPunctuationAll x Source # | |
Defined in Predicate.Prelude type PP IsPunctuationAll x :: Type Source # eval :: MonadEval m => Proxy IsPunctuationAll -> POpts -> x -> m (TT (PP IsPunctuationAll x)) Source # | |
type PP IsPunctuationAll x Source # | |
Defined in Predicate.Prelude |
data IsControlAll Source #
Instances
P IsControlAllT x => P IsControlAll x Source # | |
Defined in Predicate.Prelude type PP IsControlAll x :: Type Source # eval :: MonadEval m => Proxy IsControlAll -> POpts -> x -> m (TT (PP IsControlAll x)) Source # | |
type PP IsControlAll x Source # | |
Defined in Predicate.Prelude |
data IsHexDigitAll Source #
Instances
P IsHexDigitAllT x => P IsHexDigitAll x Source # | |
Defined in Predicate.Prelude type PP IsHexDigitAll x :: Type Source # eval :: MonadEval m => Proxy IsHexDigitAll -> POpts -> x -> m (TT (PP IsHexDigitAll x)) Source # | |
type PP IsHexDigitAll x Source # | |
Defined in Predicate.Prelude |
data IsOctDigitAll Source #
Instances
P IsOctDigitAllT x => P IsOctDigitAll x Source # | |
Defined in Predicate.Prelude type PP IsOctDigitAll x :: Type Source # eval :: MonadEval m => Proxy IsOctDigitAll -> POpts -> x -> m (TT (PP IsOctDigitAll x)) Source # | |
type PP IsOctDigitAll x Source # | |
Defined in Predicate.Prelude |
data IsSeparatorAll Source #
Instances
P IsSeparatorAllT x => P IsSeparatorAll x Source # | |
Defined in Predicate.Prelude type PP IsSeparatorAll x :: Type Source # eval :: MonadEval m => Proxy IsSeparatorAll -> POpts -> x -> m (TT (PP IsSeparatorAll x)) Source # | |
type PP IsSeparatorAll x Source # | |
Defined in Predicate.Prelude |
data IsLatin1All Source #
Instances
P IsLatin1AllT x => P IsLatin1All x Source # | |
Defined in Predicate.Prelude type PP IsLatin1All x :: Type Source # eval :: MonadEval m => Proxy IsLatin1All -> POpts -> x -> m (TT (PP IsLatin1All x)) Source # | |
type PP IsLatin1All x Source # | |
Defined in Predicate.Prelude |
datetime expressions
data FormatTimeP p q Source #
type level expression representing a formatted time
similar to formatTime
using a type level Symbol
to get the formatting string
>>>
pz @(FormatTimeP "%F %T" Id) (readNote @LocalTime "invalid localtime" "2019-05-24 05:19:59")
PresentT "2019-05-24 05:19:59"
>>>
pz @(FormatTimeP (Fst Id) (Snd Id)) ("the date is %d/%m/%Y", readNote @Day "invalid day" "2019-05-24")
PresentT "the date is 24/05/2019"
Instances
(PP p x ~ String, FormatTime (PP q x), P p x, Show (PP q x), P q x) => P (FormatTimeP p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (FormatTimeP p q) x :: Type Source # eval :: MonadEval m => Proxy (FormatTimeP p q) -> POpts -> x -> m (TT (PP (FormatTimeP p q) x)) Source # | |
type PP (FormatTimeP p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data ParseTimeP (t :: Type) p q Source #
Instances
P (ParseTimePT t p q) x => P (ParseTimeP t p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ParseTimeP t p q) x :: Type Source # eval :: MonadEval m => Proxy (ParseTimeP t p q) -> POpts -> x -> m (TT (PP (ParseTimeP t p q) x)) Source # | |
type PP (ParseTimeP t p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data ParseTimeP' t p q Source #
similar to parseTimeM
where 't' is the ParseTime
type, 'p' is the datetime format and 'q' points to the content to parse
>>>
pz @(ParseTimeP LocalTime "%F %T" Id) "2019-05-24 05:19:59"
PresentT 2019-05-24 05:19:59
>>>
pz @(ParseTimeP LocalTime "%F %T" "2019-05-24 05:19:59") (Right "never used")
PresentT 2019-05-24 05:19:59
keeping 'q' as we might want to extract from a tuple
Instances
(ParseTime (PP t a), Typeable (PP t a), Show (PP t a), P p a, P q a, PP p a ~ String, PP q a ~ String) => P (ParseTimeP' t p q :: Type) a Source # | |
Defined in Predicate.Prelude type PP (ParseTimeP' t p q) a :: Type Source # eval :: MonadEval m => Proxy (ParseTimeP' t p q) -> POpts -> a -> m (TT (PP (ParseTimeP' t p q) a)) Source # | |
type PP (ParseTimeP' t p q :: Type) a Source # | |
Defined in Predicate.Prelude |
data ParseTimes (t :: Type) p q Source #
Instances
P (ParseTimesT t p q) x => P (ParseTimes t p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ParseTimes t p q) x :: Type Source # eval :: MonadEval m => Proxy (ParseTimes t p q) -> POpts -> x -> m (TT (PP (ParseTimes t p q) x)) Source # | |
type PP (ParseTimes t p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data ParseTimes' t p q Source #
A convenience method to match against many different datetime formats to find a match
>>>
pz @(ParseTimes LocalTime '["%Y-%m-%d %H:%M:%S", "%m/%d/%y %H:%M:%S", "%B %d %Y %H:%M:%S", "%Y-%m-%dT%H:%M:%S"] "03/11/19 01:22:33") ()
PresentT 2019-03-11 01:22:33
>>>
pz @(ParseTimes LocalTime (Fst Id) (Snd Id)) (["%Y-%m-%d %H:%M:%S", "%m/%d/%y %H:%M:%S", "%B %d %Y %H:%M:%S", "%Y-%m-%dT%H:%M:%S"], "03/11/19 01:22:33")
PresentT 2019-03-11 01:22:33
Instances
(ParseTime (PP t a), Typeable (PP t a), Show (PP t a), P p a, P q a, PP p a ~ [String], PP q a ~ String) => P (ParseTimes' t p q :: Type) a Source # | |
Defined in Predicate.Prelude type PP (ParseTimes' t p q) a :: Type Source # eval :: MonadEval m => Proxy (ParseTimes' t p q) -> POpts -> a -> m (TT (PP (ParseTimes' t p q) a)) Source # | |
type PP (ParseTimes' t p q :: Type) a Source # | |
Defined in Predicate.Prelude |
create a Day
from three int values passed in as year month and day
>>>
pz @(MkDay '(1,2,3) >> Just Id) ()
PresentT 0001-02-03
>>>
pz @(Just (MkDay '(1,2,3))) 1
PresentT 0001-02-03
>>>
pz @(MkDay Id) (2019,12,30)
PresentT (Just 2019-12-30)
>>>
pz @(MkDay' (Fst Id) (Snd Id) (Thd Id)) (2019,99,99999)
PresentT Nothing
>>>
pz @(MkDay Id) (1999,3,13)
PresentT (Just 1999-03-13)
uncreate a Day
returning year month and day
>>>
pz @(UnMkDay Id) (readNote "invalid day" "2019-12-30")
PresentT (2019,12,30)
data MkDayExtra p Source #
Instances
P (MkDayExtraT p) x => P (MkDayExtra p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (MkDayExtra p) x :: Type Source # eval :: MonadEval m => Proxy (MkDayExtra p) -> POpts -> x -> m (TT (PP (MkDayExtra p) x)) Source # | |
type PP (MkDayExtra p :: Type) x Source # | |
Defined in Predicate.Prelude |
data MkDayExtra' p q r Source #
create a Day
+ Week + Day of Week from three int values passed in as year month and day
>>>
pz @(MkDayExtra '(1,2,3) >> Just Id >> Fst Id) ()
PresentT 0001-02-03
>>>
pz @(Fst (Just (MkDayExtra '(1,2,3)))) 1
PresentT 0001-02-03
>>>
pz @(MkDayExtra Id) (2019,12,30)
PresentT (Just (2019-12-30,1,1))
>>>
pz @(MkDayExtra' (Fst Id) (Snd Id) (Thd Id)) (2019,99,99999)
PresentT Nothing
>>>
pz @(MkDayExtra Id) (1999,3,13)
PresentT (Just (1999-03-13,10,6))
Instances
(P p x, P q x, P r x, PP p x ~ Int, PP q x ~ Int, PP r x ~ Int) => P (MkDayExtra' p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (MkDayExtra' p q r) x :: Type Source # eval :: MonadEval m => Proxy (MkDayExtra' p q r) -> POpts -> x -> m (TT (PP (MkDayExtra' p q r) x)) Source # | |
type PP (MkDayExtra' p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
data ToWeekDate p Source #
get day of week
>>>
pz @(Just (MkDay '(2020,7,11)) >> '(UnMkDay Id, ToWeekYear Id,ToWeekDate Id)) ()
PresentT ((2020,7,11),28,(6,"Saturday"))
Instances
(P p x, PP p x ~ Day) => P (ToWeekDate p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ToWeekDate p) x :: Type Source # eval :: MonadEval m => Proxy (ToWeekDate p) -> POpts -> x -> m (TT (PP (ToWeekDate p) x)) Source # | |
type PP (ToWeekDate p :: Type) x Source # | |
Defined in Predicate.Prelude |
data ToWeekYear p Source #
get week number of the year
>>>
pz @(Just (MkDay '(2020,7,11)) >> ToWeekYear Id) ()
PresentT 28
Instances
(P p x, PP p x ~ Day) => P (ToWeekYear p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ToWeekYear p) x :: Type Source # eval :: MonadEval m => Proxy (ToWeekYear p) -> POpts -> x -> m (TT (PP (ToWeekYear p) x)) Source # | |
type PP (ToWeekYear p :: Type) x Source # | |
Defined in Predicate.Prelude |
extract Day
from a DateTime
>>>
pz @(ReadP UTCTime Id >> ToDay Id) "2020-07-06 12:11:13Z"
PresentT 2020-07-06
extract TimeOfDay
from DateTime
>>>
pz @(ReadP UTCTime Id >> ToDay Id) "2020-07-06 12:11:13Z"
PresentT 2020-07-06
create a TimeOfDay
from three int values passed in as year month and day
>>>
pz @(MkTime '(1,2,3 % 12345)) ()
PresentT 01:02:00.000243013365
>>>
pz @(MkTime Id) (12,13,65)
PresentT 12:13:65
>>>
pz @(MkTime' (Fst Id) (Snd Id) (Thd Id)) (13,99,99999)
PresentT 13:99:99999
>>>
pz @(MkTime Id) (17,3,13)
PresentT 17:03:13
uncreate a TimeOfDay
returning hour minute seconds picoseconds
>>>
pz @(ReadP UTCTime "2019-01-01 12:13:14.1234Z" >> ToTime Id >> UnMkTime Id) ()
PresentT (12,13,70617 % 5000)
>>>
pz @(ReadP UTCTime Id >> ToTime Id >> UnMkTime Id) "2020-07-22 08:01:14.127Z"
PresentT (8,1,14127 % 1000)
>>>
pz @(ReadP ZonedTime Id >> '(UnMkDay (ToDay Id), UnMkTime (ToTime Id))) "2020-07-11 11:41:12.333 CET"
PresentT ((2020,7,11),(11,41,12333 % 1000))
data PosixToUTCTime p Source #
convert posix time (seconds since 01-01-1970) to UTCTime
>>>
pl @(PosixToUTCTime Id) 1593384312
Present 2020-06-28 22:45:12 UTC (PosixToUTCTime 2020-06-28 22:45:12 UTC | 1593384312 % 1) PresentT 2020-06-28 22:45:12 UTC
>>>
pl @(PosixToUTCTime Id >> UTCTimeToPosix Id) 1593384312
Present 1593384312 % 1 ((>>) 1593384312 % 1 | {UTCTimeToPosix 1593384312 % 1 | 2020-06-28 22:45:12 UTC}) PresentT (1593384312 % 1)
>>>
pl @(PosixToUTCTime (Id % 1000)) 1593384312000
Present 2020-06-28 22:45:12 UTC (PosixToUTCTime 2020-06-28 22:45:12 UTC | 1593384312 % 1) PresentT 2020-06-28 22:45:12 UTC
>>>
pl @(PosixToUTCTime Id) (3600*4+60*7+12)
Present 1970-01-01 04:07:12 UTC (PosixToUTCTime 1970-01-01 04:07:12 UTC | 14832 % 1) PresentT 1970-01-01 04:07:12 UTC
>>>
pz @(Rescan "^Date\\((\\d+)([^\\)]+)\\)" Id >> Head Id >> Snd Id >> ReadP Integer (Id !! 0) >> PosixToUTCTime (Id % 1000)) "Date(1530144000000+0530)"
PresentT 2018-06-28 00:00:00 UTC
Instances
(PP p x ~ Rational, P p x) => P (PosixToUTCTime p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (PosixToUTCTime p) x :: Type Source # eval :: MonadEval m => Proxy (PosixToUTCTime p) -> POpts -> x -> m (TT (PP (PosixToUTCTime p) x)) Source # | |
type PP (PosixToUTCTime p :: Type) x Source # | |
Defined in Predicate.Prelude |
data UTCTimeToPosix p Source #
convert UTCTime
to posix time (seconds since 01-01-1970)
>>>
pl @(ReadP UTCTime Id >> UTCTimeToPosix Id) "2020-06-28 22:45:12 UTC"
Present 1593384312 % 1 ((>>) 1593384312 % 1 | {UTCTimeToPosix 1593384312 % 1 | 2020-06-28 22:45:12 UTC}) PresentT (1593384312 % 1)
>>>
pz @(Rescan "^Date\\((\\d+)([^\\)]+)\\)" Id >> Head Id >> Snd Id >> ((ReadP Integer (Id !! 0) >> PosixToUTCTime (Id % 1000)) &&& ReadP TimeZone (Id !! 1))) "Date(1530144000000+0530)"
PresentT (2018-06-28 00:00:00 UTC,+0530)
not so useful: instead use ParseTimeP FormatTimeP with %s %q %z etc
>>>
pz @(ParseTimeP ZonedTime "%s%Q%z" Id) "153014400.000+0530"
PresentT 1974-11-07 05:30:00 +0530
Instances
(PP p x ~ UTCTime, P p x) => P (UTCTimeToPosix p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (UTCTimeToPosix p) x :: Type Source # eval :: MonadEval m => Proxy (UTCTimeToPosix p) -> POpts -> x -> m (TT (PP (UTCTimeToPosix p) x)) Source # | |
type PP (UTCTimeToPosix p :: Type) x Source # | |
Defined in Predicate.Prelude |
numeric expressions
fractional division
>>>
pz @(Fst Id / Snd Id) (13,2)
PresentT 6.5
>>>
pz @(ToRational 13 / Id) 0
FailT "(/) zero denominator"
>>>
pz @(12 % 7 / 14 % 5 + Id) 12.4
PresentT (3188 % 245)
similar to negate
>>>
pz @(Negate Id) 14
PresentT (-14)
>>>
pz @(Negate (Fst Id * Snd Id)) (14,3)
PresentT (-42)
>>>
pz @(Negate (15 -% 4)) "abc"
PresentT (15 % 4)
>>>
pz @(Negate (15 % 3)) ()
PresentT ((-5) % 1)
>>>
pz @(Negate (Fst Id % Snd Id)) (14,3)
PresentT ((-14) % 3)
similar to abs
>>>
pz @(Abs Id) (-14)
PresentT 14
>>>
pz @(Abs (Snd Id)) ("xx",14)
PresentT 14
>>>
pz @(Abs Id) 0
PresentT 0
>>>
pz @(Abs (Negate 44)) "aaa"
PresentT 44
similar to signum
>>>
pz @(Signum Id) (-14)
PresentT (-1)
>>>
pz @(Signum Id) 14
PresentT 1
>>>
pz @(Signum Id) 0
PresentT 0
data FromInteger (t :: Type) p Source #
Instances
P (FromIntegerT t p) x => P (FromInteger t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (FromInteger t p) x :: Type Source # eval :: MonadEval m => Proxy (FromInteger t p) -> POpts -> x -> m (TT (PP (FromInteger t p) x)) Source # | |
type PP (FromInteger t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data FromInteger' t n Source #
fromInteger
function where you need to provide the type 't' of the result
>>>
pz @(FromInteger (SG.Sum _) Id) 23
PresentT (Sum {getSum = 23})
>>>
pz @(FromInteger Rational 44) 12
PresentT (44 % 1)
>>>
pz @(FromInteger Rational Id) 12
PresentT (12 % 1)
Instances
(Num (PP t a), Integral (PP n a), P n a, Show (PP t a)) => P (FromInteger' t n :: Type) a Source # | |
Defined in Predicate.Prelude type PP (FromInteger' t n) a :: Type Source # eval :: MonadEval m => Proxy (FromInteger' t n) -> POpts -> a -> m (TT (PP (FromInteger' t n) a)) Source # | |
type PP (FromInteger' t n :: Type) a Source # | |
Defined in Predicate.Prelude |
data FromIntegral (t :: Type) p Source #
Instances
P (FromIntegralT t p) x => P (FromIntegral t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (FromIntegral t p) x :: Type Source # eval :: MonadEval m => Proxy (FromIntegral t p) -> POpts -> x -> m (TT (PP (FromIntegral t p) x)) Source # | |
type PP (FromIntegral t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data FromIntegral' t n Source #
fromIntegral
function where you need to provide the type 't' of the result
>>>
pz @(FromIntegral (SG.Sum _) Id) 23
PresentT (Sum {getSum = 23})
Instances
(Num (PP t a), Integral (PP n a), P n a, Show (PP t a), Show (PP n a)) => P (FromIntegral' t n :: Type) a Source # | |
Defined in Predicate.Prelude type PP (FromIntegral' t n) a :: Type Source # eval :: MonadEval m => Proxy (FromIntegral' t n) -> POpts -> a -> m (TT (PP (FromIntegral' t n) a)) Source # | |
type PP (FromIntegral' t n :: Type) a Source # | |
Defined in Predicate.Prelude |
truncate
function where you need to provide the type 't' of the result
>>>
pz @(Truncate Int Id) (23 % 5)
PresentT 4
ceiling
function where you need to provide the type 't' of the result
>>>
pz @(Ceiling Int Id) (23 % 5)
PresentT 5
floor
function where you need to provide the type 't' of the result
>>>
pz @(Floor Int Id) (23 % 5)
PresentT 4
similar to even
>>>
pz @(Map Even Id) [9,-4,12,1,2,3]
PresentT [False,True,True,False,True,False]
>>>
pz @(Map '(Even,Odd) Id) [9,-4,12,1,2,3]
PresentT [(False,True),(True,False),(True,False),(False,True),(True,False),(False,True)]
similar to div
>>>
pz @(Div (Fst Id) (Snd Id)) (10,4)
PresentT 2
>>>
pz @(Div (Fst Id) (Snd Id)) (10,0)
FailT "Div zero denominator"
similar to mod
>>>
pz @(Mod (Fst Id) (Snd Id)) (10,3)
PresentT 1
>>>
pz @(Mod (Fst Id) (Snd Id)) (10,0)
FailT "Mod zero denominator"
similar to divMod
>>>
pz @(DivMod (Fst Id) (Snd Id)) (10,3)
PresentT (3,1)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (10,-3)
PresentT (-4,-2)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (-10,3)
PresentT (-4,2)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (-10,-3)
PresentT (3,-1)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (10,0)
FailT "DivMod zero denominator"
similar to quotRem
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (10,3)
PresentT (3,1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (10,-3)
PresentT (-3,1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (-10,-3)
PresentT (3,-1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (-10,3)
PresentT (-3,-1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (10,0)
FailT "QuotRem zero denominator"
similar to logBase
>>>
pz @(Fst Id `LogBase` Snd Id >> Truncate Int Id) (10,12345)
PresentT 4
similar to 'GHC.Real.(^)'
>>>
pz @(Fst Id ^ Snd Id) (10,4)
PresentT 10000
similar to 'GHC.Float.(**)'
>>>
pz @(Fst Id ** Snd Id) (10,4)
PresentT 10000.0
rational numbers
creates a Rational
value
>>>
pz @(Id < 21 % 5) (-3.1)
TrueT
>>>
pz @(Id < 21 % 5) 4.5
FalseT
>>>
pz @(Fst Id % Snd Id) (13,2)
PresentT (13 % 2)
>>>
pz @(13 % Id) 0
FailT "(%) zero denominator"
>>>
pz @(4 % 3 + 5 % 7) "asfd"
PresentT (43 % 21)
>>>
pz @(4 -% 7 * 5 -% 3) "asfd"
PresentT (20 % 21)
>>>
pz @(Negate (14 % 3)) ()
PresentT ((-14) % 3)
>>>
pz @(14 % 3) ()
PresentT (14 % 3)
>>>
pz @(Negate (14 % 3) ==! FromIntegral _ (Negate 5)) ()
PresentT GT
>>>
pz @(14 -% 3 ==! 5 -% 1) "aa"
PresentT GT
>>>
pz @(Negate (14 % 3) ==! Negate 5 % 2) ()
PresentT LT
>>>
pz @(14 -% 3 * 5 -% 1) ()
PresentT (70 % 3)
>>>
pz @(14 % 3 ==! 5 % 1) ()
PresentT LT
>>>
pz @(15 % 3 / 4 % 2) ()
PresentT (5 % 2)
data ToRational p Source #
toRational
function
>>>
pz @(ToRational Id) 23.5
PresentT (47 % 2)
Instances
(a ~ PP p x, Show a, Real a, P p x) => P (ToRational p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ToRational p) x :: Type Source # eval :: MonadEval m => Proxy (ToRational p) -> POpts -> x -> m (TT (PP (ToRational p) x)) Source # | |
type PP (ToRational p :: Type) x Source # | |
Defined in Predicate.Prelude |
data FromRational (t :: Type) p Source #
Instances
P (FromRationalT t p) x => P (FromRational t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (FromRational t p) x :: Type Source # eval :: MonadEval m => Proxy (FromRational t p) -> POpts -> x -> m (TT (PP (FromRational t p) x)) Source # | |
type PP (FromRational t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data FromRational' t r Source #
fromRational
function where you need to provide the type 't' of the result
>>>
pz @(FromRational Rational Id) 23.5
PresentT (47 % 2)
Instances
(P r a, PP r a ~ Rational, Show (PP t a), Fractional (PP t a)) => P (FromRational' t r :: Type) a Source # | |
Defined in Predicate.Prelude type PP (FromRational' t r) a :: Type Source # eval :: MonadEval m => Proxy (FromRational' t r) -> POpts -> a -> m (TT (PP (FromRational' t r) a)) Source # | |
type PP (FromRational' t r :: Type) a Source # | |
Defined in Predicate.Prelude |
proxy expressions
converts a value to a Proxy
: the same as '\'Proxy'
>>>
pz @MkProxy 'x'
PresentT Proxy
read / show expressions
similar to show
>>>
pz @(ShowP Id) [4,8,3,9]
PresentT "[4,8,3,9]"
>>>
pz @(ShowP Id) 'x'
PresentT "'x'"
>>>
pz @(ShowP (42 -% 10)) 'x'
PresentT "(-21) % 5"
uses the Read
of the given type 't' and 'p' which points to the content to read
>>>
pz @(ReadP Rational Id) "4 % 5"
PresentT (4 % 5)
>>>
pz @(Between (ReadP Day "2017-04-11") (ReadP Day "2018-12-30") (ReadP Day Id)) "2018-10-12"
TrueT
>>>
pz @(Between (ReadP Day "2017-04-11") (ReadP Day "2018-12-30") (ReadP Day Id)) "2016-10-12"
FalseT
emulates ReadP
data ReadMaybe' t p Source #
Read but returns the Maybe of the value and any remaining unparsed string
>>>
pz @(ReadMaybe Int Id) "123x"
PresentT (Just (123,"x"))
>>>
pz @(ReadMaybe Int Id) "123"
PresentT (Just (123,""))
>>>
pz @(ReadMaybe Int Id) "x123"
PresentT Nothing
Instances
(P p x, PP p x ~ String, Typeable (PP t x), Show (PP t x), Read (PP t x)) => P (ReadMaybe' t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ReadMaybe' t p) x :: Type Source # eval :: MonadEval m => Proxy (ReadMaybe' t p) -> POpts -> x -> m (TT (PP (ReadMaybe' t p) x)) Source # | |
type PP (ReadMaybe' t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data ReadBase' t (n :: Nat) p Source #
Read a number using base 2 through a maximum of 36
>>>
pz @(ReadBase Int 16 Id) "00feD"
PresentT 4077
>>>
pz @(ReadBase Int 16 Id) "-ff"
PresentT (-255)
>>>
pz @(ReadBase Int 2 Id) "10010011"
PresentT 147
>>>
pz @(ReadBase Int 8 Id) "Abff"
FailT "invalid base 8"
>>>
pl @(ReadBase Int 16 Id >> GuardSimple (Id > 0xffff) >> ShowBase 16 Id) "12344"
Present "12344" ((>>) "12344" | {ShowBase(16) 12344 | 74564}) PresentT "12344"
>>>
:set -XBinaryLiterals
>>>
pz @(ReadBase Int 16 Id >> GuardSimple (Id > 0b10011111) >> ShowBase 16 Id) "7f"
FailT "(127 > 159)"
data ShowBase (n :: Nat) p Source #
Display a number at base 2 to 36, similar to showIntAtBase
but supports signed numbers
>>>
pz @(ShowBase 16 Id) 4077
PresentT "fed"
>>>
pz @(ShowBase 16 Id) (-255)
PresentT "-ff"
>>>
pz @(ShowBase 2 Id) 147
PresentT "10010011"
>>>
pz @(ShowBase 2 (Negate 147)) "whatever"
PresentT "-10010011"
aeson expressions
data ParseJson' t p Source #
parse json data
>>>
pl @(ParseJson (Int,String) Id) "[10,\"abc\"]"
Present (10,"abc") (ParseJson (Int,[Char]) (10,"abc")) PresentT (10,"abc")
>>>
pl @(ParseJson (Int,String) Id) "[10,\"abc\",99]"
Error ParseJson (Int,[Char])([10,"abc",...) Error in $ (ParseJson (Int,[Char]) failed Error in $: cannot unpack array of length 3 into a tuple of length 2 | [10,"abc",99]) FailT "ParseJson (Int,[Char])([10,\"abc\",...) Error in $"
>>>
pl @(ParseJson (Int,Bool) (FromString _ Id)) ("[1,true]" :: String)
Present (1,True) (ParseJson (Int,Bool) (1,True)) PresentT (1,True)
>>>
pl @(ParseJson (Int,Bool) Id) (A.encode (1,True))
Present (1,True) (ParseJson (Int,Bool) (1,True)) PresentT (1,True)
>>>
pl @(ParseJson () Id) "[1,true]"
Error ParseJson ()([1,true]) Error in $ (ParseJson () failed Error in $: parsing () failed, expected an empty array | [1,true]) FailT "ParseJson ()([1,true]) Error in $"
Instances
(P p x, PP p x ~ ByteString, Typeable (PP t x), Show (PP t x), FromJSON (PP t x)) => P (ParseJson' t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ParseJson' t p) x :: Type Source # eval :: MonadEval m => Proxy (ParseJson' t p) -> POpts -> x -> m (TT (PP (ParseJson' t p) x)) Source # | |
type PP (ParseJson' t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data EncodeJson p Source #
encode json
>>>
pl @(EncodeJson Id) (10,"def")
Present "[10,\"def\"]" (EncodeJson [10,"def"]) PresentT "[10,\"def\"]"
>>>
pl @(EncodeJson Id >> ParseJson (Int,Bool) Id) (1,True)
Present (1,True) ((>>) (1,True) | {ParseJson (Int,Bool) (1,True)}) PresentT (1,True)
Instances
(ToJSON (PP p x), P p x) => P (EncodeJson p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (EncodeJson p) x :: Type Source # eval :: MonadEval m => Proxy (EncodeJson p) -> POpts -> x -> m (TT (PP (EncodeJson p) x)) Source # | |
type PP (EncodeJson p :: Type) x Source # | |
Defined in Predicate.Prelude |
data EncodeJsonFile p q Source #
encode a json file
Instances
(PP p x ~ String, P p x, ToJSON (PP q x), P q x) => P (EncodeJsonFile p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (EncodeJsonFile p q) x :: Type Source # eval :: MonadEval m => Proxy (EncodeJsonFile p q) -> POpts -> x -> m (TT (PP (EncodeJsonFile p q) x)) Source # | |
type PP (EncodeJsonFile p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data ParseJsonFile' t p Source #
parse a json file
>>>
pz @(ParseJsonFile [A.Value] "test1.json" >> Id !! 2) ()
PresentT (Object (fromList [("lastName",String "Doe"),("age",Number 45.0),("firstName",String "John"),("likesPizza",Bool False)]))
Instances
(P p x, PP p x ~ String, Typeable (PP t x), Show (PP t x), FromJSON (PP t x)) => P (ParseJsonFile' t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ParseJsonFile' t p) x :: Type Source # eval :: MonadEval m => Proxy (ParseJsonFile' t p) -> POpts -> x -> m (TT (PP (ParseJsonFile' t p) x)) Source # | |
type PP (ParseJsonFile' t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data ParseJsonFile (t :: Type) p Source #
Instances
P (ParseJsonFileT t p) x => P (ParseJsonFile t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ParseJsonFile t p) x :: Type Source # eval :: MonadEval m => Proxy (ParseJsonFile t p) -> POpts -> x -> m (TT (PP (ParseJsonFile t p) x)) Source # | |
type PP (ParseJsonFile t p :: Type) x Source # | |
Defined in Predicate.Prelude |
arrow expressions
data p &&& q infixr 3 Source #
similar to &&&
data p *** q infixr 3 Source #
similar to ***
>>>
pz @(Pred Id *** ShowP Id) (13, True)
PresentT (12,"True")
>>>
pl @(FlipT (***) Len (Id * 12)) (99,"cdef")
Present (1188,4) ((***) (1188,4) | (99,"cdef")) PresentT (1188,4)
data p ||| q infixr 2 Source #
similar |||
>>>
pz @(Pred Id ||| Id) (Left 13)
PresentT 12
>>>
pz @(ShowP Id ||| Id) (Right "hello")
PresentT "hello"
data p +++ q infixr 2 Source #
similar +++
>>>
pz @(Pred Id +++ Id) (Left 13)
PresentT (Left 12)
>>>
pz @(ShowP Id +++ Reverse) (Right "hello")
PresentT (Right "olleh")
compare expressions
similar to compare
>>>
pz @(Fst Id ==! Snd Id) (10,9)
PresentT GT
>>>
pz @(14 % 3 ==! Fst Id -% Snd Id) (-10,7)
PresentT GT
>>>
pz @(Fst Id ==! Snd Id) (10,11)
PresentT LT
>>>
pz @(Snd Id ==! (Fst Id >> Snd Id >> Head Id)) (('x',[10,12,13]),10)
PresentT EQ
>>>
pz @(Snd Id ==! Head (Snd (Fst Id))) (('x',[10,12,13]),10)
PresentT EQ
type OrdI p q = p ===~ q Source #
compare two strings ignoring case
>>>
pz @(Fst Id ===~ Snd Id) ("abC","aBc")
PresentT EQ
>>>
pz @(Fst Id ===~ Snd Id) ("abC","DaBc")
PresentT LT
data Cmp (o :: OrderingP) p q Source #
compare two values using the given ordering 'o'
>>>
pl @(Lt 4) 123
False (123 < 4) FalseT
>>>
pl @(Lt 4) 1
True (1 < 4) TrueT
>>>
pl @(Negate 7 <..> 20) (-4)
True (-7 <= -4 <= 20) TrueT
>>>
pl @(Negate 7 <..> 20) 21
False (21 <= 20) FalseT
data CmpI (o :: OrderingP) p q Source #
compare two strings ignoring case using the given ordering 'o'
enum expressions
unbounded succ
function
>>>
pz @(Succ Id) 13
PresentT 14
>>>
pz @(Succ Id) LT
PresentT EQ
>>>
pz @(Succ Id) GT
FailT "Succ IO e=Prelude.Enum.Ordering.succ: bad argument"
unbounded pred
function
>>>
pz @(Pred Id) 13
PresentT 12
>>>
pz @(Pred Id) LT
FailT "Pred IO e=Prelude.Enum.Ordering.pred: bad argument"
fromEnum
function
>>>
pz @(FromEnum Id) 'x'
PresentT 120
unsafe toEnum
function
>>>
pz @(ToEnum Char Id) 120
PresentT 'x'
data EnumFromTo p q Source #
similar to enumFromTo
>>>
pz @(EnumFromTo 2 5) ()
PresentT [2,3,4,5]
>>>
pz @(EnumFromTo 'LT 'GT) ()
PresentT [LT,EQ,GT]
>>>
pz @(EnumFromTo 'GT 'LT) ()
PresentT []
>>>
pz @(EnumFromTo (Pred Id) (Succ Id)) (SG.Max 10)
PresentT [Max {getMax = 9},Max {getMax = 10},Max {getMax = 11}]
>>>
pz @(EnumFromTo 1 20 >> Map '(Id, (If (Id `Mod` 3 == 0) "Fizz" "" <> If (Id `Mod` 5 == 0) "Buzz" "" )) Id) 123
PresentT [(1,""),(2,""),(3,"Fizz"),(4,""),(5,"Buzz"),(6,"Fizz"),(7,""),(8,""),(9,"Fizz"),(10,"Buzz"),(11,""),(12,"Fizz"),(13,""),(14,""),(15,"FizzBuzz"),(16,""),(17,""),(18,"Fizz"),(19,""),(20,"Buzz")]
Instances
(P p x, P q x, PP p x ~ a, Show a, PP q x ~ a, Enum a) => P (EnumFromTo p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (EnumFromTo p q) x :: Type Source # eval :: MonadEval m => Proxy (EnumFromTo p q) -> POpts -> x -> m (TT (PP (EnumFromTo p q) x)) Source # | |
type PP (EnumFromTo p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data EnumFromThenTo p q r Source #
similar to enumFromThenTo
>>>
pz @(EnumFromThenTo (ToEnum Day 10) (ToEnum Day 20) (ToEnum Day 70)) ()
PresentT [1858-11-27,1858-12-07,1858-12-17,1858-12-27,1859-01-06,1859-01-16,1859-01-26]
>>>
pz @(EnumFromThenTo (ReadP Day "2020-01-12") (ReadP Day "2020-02-12") (ReadP Day "2020-08-12")) ()
PresentT [2020-01-12,2020-02-12,2020-03-14,2020-04-14,2020-05-15,2020-06-15,2020-07-16]
Instances
(P p x, P q x, P r x, PP p x ~ a, Show a, PP q x ~ a, PP r x ~ a, Enum a) => P (EnumFromThenTo p q r :: Type) x Source # | |
Defined in Predicate.Prelude type PP (EnumFromThenTo p q r) x :: Type Source # eval :: MonadEval m => Proxy (EnumFromThenTo p q r) -> POpts -> x -> m (TT (PP (EnumFromThenTo p q r) x)) Source # | |
type PP (EnumFromThenTo p q r :: Type) x Source # | |
Defined in Predicate.Prelude |
bounded enum expressions
Instances
(PP q x ~ a, P q x, P p (Proxy a), PP p (Proxy a) ~ a, Show a, Eq a, Bounded a, Enum a) => P (SuccB p q :: Type) x Source # | bounded
|
type PP (SuccB p q :: Type) x Source # | |
Defined in Predicate.Prelude |
bounded pred
function
>>>
pz @(PredB' Id) (13 :: Int)
PresentT 12
>>>
pz @(PredB' Id) LT
FailT "Pred bounded"
data ToEnumBDef (t :: Type) def Source #
Instances
P (ToEnumBDefT t def) x => P (ToEnumBDef t def :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ToEnumBDef t def) x :: Type Source # eval :: MonadEval m => Proxy (ToEnumBDef t def) -> POpts -> x -> m (TT (PP (ToEnumBDef t def) x)) Source # | |
type PP (ToEnumBDef t def :: Type) x Source # | |
Defined in Predicate.Prelude |
data ToEnumBDef' t def Source #
bounded toEnum
function
>>>
pz @(ToEnumBDef Ordering LT) 2
PresentT GT
>>>
pz @(ToEnumBDef Ordering LT) 6
PresentT LT
>>>
pz @(ToEnumBFail Ordering) 6
FailT "ToEnum bounded"
Instances
(P def (Proxy (PP t a)), PP def (Proxy (PP t a)) ~ PP t a, Show a, Show (PP t a), Bounded (PP t a), Enum (PP t a), Integral a) => P (ToEnumBDef' t def :: Type) a Source # | |
Defined in Predicate.Prelude type PP (ToEnumBDef' t def) a :: Type Source # eval :: MonadEval m => Proxy (ToEnumBDef' t def) -> POpts -> a -> m (TT (PP (ToEnumBDef' t def) a)) Source # | |
type PP (ToEnumBDef' t def :: Type) a Source # | |
Defined in Predicate.Prelude |
data ToEnumBFail (t :: Type) Source #
Instances
P (ToEnumBFailT t) x => P (ToEnumBFail t :: Type) x Source # | |
Defined in Predicate.Prelude type PP (ToEnumBFail t) x :: Type Source # eval :: MonadEval m => Proxy (ToEnumBFail t) -> POpts -> x -> m (TT (PP (ToEnumBFail t) x)) Source # | |
type PP (ToEnumBFail t :: Type) x Source # | |
Defined in Predicate.Prelude |
wrap / unwrap expressions
unwraps a value (see _Wrapped'
)
>>>
pz @(Unwrap Id) (SG.Sum (-13))
PresentT (-13)
wraps a value (see _Wrapped'
and _Unwrapped'
)
>>>
:m + Data.List.NonEmpty
>>>
pz @(Wrap (SG.Sum _) Id) (-13)
PresentT (Sum {getSum = -13})
>>>
pz @(Wrap SG.Any (Ge 4)) 13
PresentT (Any {getAny = True})
>>>
pz @(Wrap (NonEmpty _) (Uncons >> 'Just Id)) "abcd"
PresentT ('a' :| "bcd")
similar to coerce
>>>
pz @(Coerce (SG.Sum Integer)) (Identity (-13))
PresentT (Sum {getSum = -13})
data Coerce2 (t :: k) Source #
see Coerce
: coerce over a functor
>>>
pz @(Coerce2 (SG.Sum Integer)) [Identity (-13), Identity 4, Identity 99]
PresentT [Sum {getSum = -13},Sum {getSum = 4},Sum {getSum = 99}]
>>>
pz @(Coerce2 (SG.Sum Integer)) (Just (Identity (-13)))
PresentT (Just (Sum {getSum = -13}))
>>>
pz @(Coerce2 (SG.Sum Int)) (Nothing @(Identity Int))
PresentT Nothing
list / foldable expressions
similar to map
>>>
pz @(Map (Pred Id) Id) [1..5]
PresentT [0,1,2,3,4]
similar to concat
>>>
pz @(Concat Id) ["abc","D","eF","","G"]
PresentT "abcDeFG"
>>>
pz @(Concat (Snd Id)) ('x',["abc","D","eF","","G"])
PresentT "abcDeFG"
similar to partition
>>>
pz @(Partition (Ge 3) Id) [10,4,1,7,3,1,3,5]
PresentT ([10,4,7,3,3,5],[1,1])
>>>
pz @(Partition (Prime Id) Id) [10,4,1,7,3,1,3,5]
PresentT ([7,3,3,5],[10,4,1,1])
>>>
pz @(Partition (Ge 300) Id) [10,4,1,7,3,1,3,5]
PresentT ([],[10,4,1,7,3,1,3,5])
>>>
pz @(Partition (Id < 300) Id) [10,4,1,7,3,1,3,5]
PresentT ([10,4,1,7,3,1,3,5],[])
groups values based on a function
>>>
pl @(GroupOn Ordering (Case (Failt _ "asdf") '[Id < 2, Id == 2, Id > 2] '[ 'LT, 'EQ, 'GT] Id) Id) [-4,2,5,6,7,1,2,3,4]
Present fromList [(LT,[1,-4]),(EQ,[2,2]),(GT,[4,3,7,6,5])] (GroupOn fromList [(LT,[1,-4]),(EQ,[2,2]),(GT,[4,3,7,6,5])] | s=[-4,2,5,6,7,1,2,3,4]) PresentT (fromList [(LT,[1,-4]),(EQ,[2,2]),(GT,[4,3,7,6,5])])
>>>
pl @(GroupOn Ordering (Case (Failt _ "xyzxyzxyzzyyysyfsyfydf") '[Id < 2, Id == 2, Id > 3] '[ 'LT, 'EQ, 'GT] Id) Id) [-4,2,5,6,7,1,2,3,4]
Error xyzxyzxyzzyyysyfsyfydf (GroupOn(i=7, a=3) excnt=1) FailT "xyzxyzxyzzyyysyfsyfydf"
similar to break
>>>
pz @(Break (Ge 3) Id) [10,4,1,7,3,1,3,5]
PresentT ([],[10,4,1,7,3,1,3,5])
>>>
pz @(Break (Lt 3) Id) [10,4,1,7,3,1,3,5]
PresentT ([10,4],[1,7,3,1,3,5])
data Intercalate p q Source #
intercalate two lists
>>>
pz @(Intercalate '["aB"] '["xxxx","yz","z","www","xyz"]) ()
PresentT ["xxxx","aB","yz","aB","z","aB","www","aB","xyz"]
>>>
pz @(Intercalate '[W 99,Negate 98] Id) [1..5]
PresentT [1,99,-98,2,99,-98,3,99,-98,4,99,-98,5]
>>>
pz @(Intercalate '[99,100] Id) [1..5]
PresentT [1,99,100,2,99,100,3,99,100,4,99,100,5]
Instances
(PP p x ~ [a], PP q x ~ PP p x, P p x, P q x, Show a) => P (Intercalate p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (Intercalate p q) x :: Type Source # eval :: MonadEval m => Proxy (Intercalate p q) -> POpts -> x -> m (TT (PP (Intercalate p q) x)) Source # | |
type PP (Intercalate p q :: Type) x Source # | |
Defined in Predicate.Prelude |
elem
function
>>>
pz @(Elem (Fst Id) (Snd Id)) ('x',"abcdxy")
TrueT
>>>
pz @(Elem (Fst Id) (Snd Id)) ('z',"abcdxy")
FalseT
similar to inits
>>>
pz @Inits [4,8,3,9]
PresentT [[],[4],[4,8],[4,8,3],[4,8,3,9]]
>>>
pz @Inits []
PresentT [[]]
similar to tails
>>>
pz @Tails [4,8,3,9]
PresentT [[4,8,3,9],[8,3,9],[3,9],[9],[]]
>>>
pz @Tails []
PresentT [[]]
split a list into single values
>>>
pz @(Ones Id) [4,8,3,9]
PresentT [[4],[8],[3],[9]]
>>>
pz @(Ones Id) []
PresentT []
gets the singleton value from a foldable
>>>
pl @(OneP Id) [10..15]
Error OneP 6 elements (OneP expected one element) FailT "OneP 6 elements"
>>>
pl @(OneP Id) [10]
Present 10 (OneP) PresentT 10
>>>
pl @(OneP Id) []
Error OneP empty (OneP expected one element) FailT "OneP empty"
>>>
pl @(OneP Id) (Just 10)
Present 10 (OneP) PresentT 10
>>>
pl @(OneP Id) Nothing
Error OneP empty (OneP expected one element) FailT "OneP empty"
similar to length
for Foldable
instances
>>>
pz @(Length Id) (Left "aa")
PresentT 0
>>>
pz @(Length Id) (Right "aa")
PresentT 1
>>>
pz @(Length (Right' Id)) (Right "abcd")
PresentT 4
>>>
pz @(Length (Thd (Snd Id))) (True,(23,'x',[10,9,1,3,4,2]))
PresentT 6
similar to cycle
but for a fixed number 'n'
>>>
pz @(Cycle 5 Id) [1,2]
PresentT [1,2,1,2,1]
split a list 'p' into parts using the lengths in the type level list 'ns'
>>>
pz @(SplitAts '[2,3,1,1] Id) "hello world"
PresentT ["he","llo"," ","w","orld"]
>>>
pz @(SplitAts '[2] Id) "hello world"
PresentT ["he","llo world"]
>>>
pz @(SplitAts '[10,1,1,5] Id) "hello world"
PresentT ["hello worl","d","",""]
similar to splitAt
>>>
pz @(SplitAt 4 Id) "hello world"
PresentT ("hell","o world")
>>>
pz @(SplitAt 20 Id) "hello world"
PresentT ("hello world","")
>>>
pz @(SplitAt 0 Id) "hello world"
PresentT ("","hello world")
>>>
pz @(SplitAt (Snd Id) (Fst Id)) ("hello world",4)
PresentT ("hell","o world")
>>>
pz @(SplitAt (Negate 2) Id) "hello world"
PresentT ("hello wor","ld")
splits a list pointed to by 'p' into lists of size 'n'
>>>
pz @(ChunksOf 2 Id) "abcdef"
PresentT ["ab","cd","ef"]
>>>
pz @(ChunksOf 2 Id) "abcdefg"
PresentT ["ab","cd","ef","g"]
>>>
pz @(ChunksOf 2 Id) ""
PresentT []
>>>
pz @(ChunksOf 2 Id) "a"
PresentT ["a"]
>>>
pz @IsEmpty [1,2,3,4]
FalseT
>>>
pz @IsEmpty []
TrueT
>>>
pz @IsEmpty LT
FalseT
>>>
pz @IsEmpty EQ
TrueT
similar to toList
>>>
pz @ToList ("aBc" :: String)
PresentT "aBc"
>>>
pz @ToList (Just 14)
PresentT [14]
>>>
pz @ToList Nothing
PresentT []
>>>
pz @ToList (Left "xx")
PresentT []
>>>
pz @ToList (These 12 "xx")
PresentT ["xx"]
similar to toList
>>>
pz @(ToList' Id) ("aBc" :: String)
PresentT "aBc"
>>>
pz @(ToList' Id) (Just 14)
PresentT [14]
>>>
pz @(ToList' Id) Nothing
PresentT []
>>>
pz @(ToList' Id) (Left "xx")
PresentT []
>>>
pz @(ToList' Id) (These 12 "xx")
PresentT ["xx"]
similar to itoList
>>>
pz @(IToList _ Id) ("aBc" :: String)
PresentT [(0,'a'),(1,'B'),(2,'c')]
data FromList (t :: Type) Source #
invokes fromList
>>>
import qualified Data.Set as Set
>>>
run @('OMsg "Fred" ':# 'ODebug 'DLite ':# 'ONoColor 'True) @(FromList (Set.Set Int) << '[2,1,5,5,2,5,2]) ()
Fred >>> Present fromList [1,2,5] ((>>) fromList [1,2,5] | {FromList fromList [1,2,5]}) PresentT (fromList [1,2,5])
data EmptyList' t Source #
creates an empty list of the given type
>>>
pz @(Id :+ EmptyList _) 99
PresentT [99]
Instances
P (EmptyList' t :: Type) x Source # | |
Defined in Predicate.Prelude type PP (EmptyList' t) x :: Type Source # eval :: MonadEval m => Proxy (EmptyList' t) -> POpts -> x -> m (TT (PP (EmptyList' t) x)) Source # | |
type PP (EmptyList' t :: Type) x Source # | |
Defined in Predicate.Prelude |
creates a singleton from a value
>>>
pz @(Singleton (Char1 "aBc")) ()
PresentT "a"
>>>
pz @(Singleton Id) False
PresentT [False]
>>>
pz @(Singleton (Snd Id)) (False,"hello")
PresentT ["hello"]
similar to reverse
>>>
pz @Reverse [1,2,4]
PresentT [4,2,1]
>>>
pz @Reverse "AbcDeF"
PresentT "FeDcbA"
reverses using reversing
>>>
pz @ReverseL (T.pack "AbcDeF")
PresentT "FeDcbA"
>>>
pz @ReverseL ("AbcDeF" :: String)
PresentT "FeDcbA"
sort a list
>>>
pz @(SortOn (Fst Id) Id) [(10,"abc"), (3,"def"), (4,"gg"), (10,"xyz"), (1,"z")]
PresentT [(1,"z"),(3,"def"),(4,"gg"),(10,"abc"),(10,"xyz")]
>>>
pz @(SortBy (OrdP (Snd Id) (Fst Id)) Id) [(10,"ab"),(4,"x"),(20,"bbb")]
PresentT [(20,"bbb"),(10,"ab"),(4,"x")]
>>>
pz @(SortBy 'LT Id) [1,5,2,4,7,0]
PresentT [1,5,2,4,7,0]
>>>
pz @(SortBy 'GT Id) [1,5,2,4,7,0]
PresentT [0,7,4,2,5,1]
>>>
pz @(SortBy ((Fst (Fst Id) ==! Fst (Snd Id)) <> (Snd (Fst Id) ==! Snd (Snd Id))) Id) [(10,"ab"),(4,"x"),(20,"bbb"),(4,"a"),(4,"y")]
PresentT [(4,"a"),(4,"x"),(4,"y"),(10,"ab"),(20,"bbb")]
>>>
pz @(SortBy ((Fst (Fst Id) ==! Fst (Snd Id)) <> (Snd (Snd Id) ==! Snd (Fst Id))) Id) [(10,"ab"),(4,"x"),(20,"bbb"),(4,"a"),(4,"y")]
PresentT [(4,"y"),(4,"x"),(4,"a"),(10,"ab"),(20,"bbb")]
data SortOnDesc p q Source #
Instances
P (SortOnDescT p q) x => P (SortOnDesc p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (SortOnDesc p q) x :: Type Source # eval :: MonadEval m => Proxy (SortOnDesc p q) -> POpts -> x -> m (TT (PP (SortOnDesc p q) x)) Source # | |
type PP (SortOnDesc p q :: Type) x Source # | |
Defined in Predicate.Prelude |
overloaded list expressions
invokes toList
>>>
pz @ToListExt (M.fromList [(1,'x'),(4,'y')])
PresentT [(1,'x'),(4,'y')]
>>>
pz @ToListExt (T.pack "abc")
PresentT "abc"
data FromListExt (t :: Type) Source #
invokes fromList
requires the OverloadedLists extension
>>>
:set -XOverloadedLists
>>>
pz @(FromListExt (M.Map _ _)) [(4,"x"),(5,"dd")]
PresentT (fromList [(4,"x"),(5,"dd")])
Instances
(Show l, IsList l, l ~ l') => P (FromListExt l' :: Type) l Source # | |
Defined in Predicate.Prelude type PP (FromListExt l') l :: Type Source # eval :: MonadEval m => Proxy (FromListExt l') -> POpts -> l -> m (TT (PP (FromListExt l') l)) Source # | |
type PP (FromListExt l' :: Type) l Source # | |
Defined in Predicate.Prelude |
maybe expressions
data MkNothing' t Source #
Instances
P (MkNothing' t :: Type) a Source # | |
Defined in Predicate.Prelude type PP (MkNothing' t) a :: Type Source # eval :: MonadEval m => Proxy (MkNothing' t) -> POpts -> a -> m (TT (PP (MkNothing' t) a)) Source # | |
type PP (MkNothing' t :: Type) a Source # | |
Defined in Predicate.Prelude |
Just
constructor
>>>
pz @(MkJust Id) 44
PresentT (Just 44)
similar to catMaybes
>>>
pl @(CatMaybes Id) [Just 'a',Nothing,Just 'c',Just 'd',Nothing]
Present "acd" (Concat "acd" | ["a","","c","d",""]) PresentT "acd"
tries to extract a
from Maybe a
otherwise it fails
>>>
pz @(Just Id) (Just "abc")
PresentT "abc"
>>>
pz @(Just Id) Nothing
FailT "Just(empty)"
extract the value from a Maybe
otherwise use the default value
>>>
pz @(JustDef (1 % 4) Id) (Just 20.4)
PresentT (102 % 5)
>>>
pz @(JustDef (1 % 4) Id) Nothing
PresentT (1 % 4)
>>>
pz @(JustDef (MEmptyT _) Id) (Just "xy")
PresentT "xy"
>>>
pz @(JustDef (MEmptyT _) Id) Nothing
PresentT ()
>>>
pz @(JustDef (MEmptyT (SG.Sum _)) Id) Nothing
PresentT (Sum {getSum = 0})
extract the value from a Maybe
or fail
>>>
pz @(JustFail "nope" Id) (Just 99)
PresentT 99
>>>
pz @(JustFail "nope" Id) Nothing
FailT "nope"
>>>
pz @(JustFail (PrintF "oops=%d" (Snd Id)) (Fst Id)) (Nothing, 123)
FailT "oops=123"
>>>
pz @(JustFail (PrintF "oops=%d" (Snd Id)) (Fst Id)) (Just 'x', 123)
PresentT 'x'
similar to maybe
provides a Proxy to the result of 'q' but does not provide the surrounding context
>>>
pz @(MaybeIn "foundnothing" (ShowP (Pred Id))) (Just 20)
PresentT "19"
>>>
pz @(MaybeIn "found nothing" (ShowP (Pred Id))) Nothing
PresentT "found nothing"
Convenient method to convert a value 'p' to a Maybe
based on a predicate '\b\'
if '\b\' then Just 'p' else Nothing
>>>
pz @(MaybeBool (Id > 4) Id) 24
PresentT (Just 24)
>>>
pz @(MaybeBool (Id > 4) Id) (-5)
PresentT Nothing
either expressions
data PartitionEithers Source #
similar to partitionEithers
>>>
pz @PartitionEithers [Left 'a',Right 2,Left 'c',Right 4,Right 99]
PresentT ("ac",[2,4,99])
>>>
pz @PartitionEithers [Right 2,Right 4,Right 99]
PresentT ([],[2,4,99])
>>>
pz @PartitionEithers [Left 'a',Left 'c']
PresentT ("ac",[])
>>>
pz @PartitionEithers ([] :: [Either () Int])
PresentT ([],[])
Instances
(Show a, Show b) => P PartitionEithers [Either a b] Source # | |
Defined in Predicate.Prelude | |
type PP PartitionEithers [Either a b] Source # | |
Defined in Predicate.Prelude |
Left
constructor
>>>
pz @(MkLeft _ Id) 44
PresentT (Left 44)
Right
constructor
>>>
pz @(MkRight _ Id) 44
PresentT (Right 44)
extract the Left value from an Either
otherwise use the default value
if there is no Left value then p is passed the Right value and the whole context
>>>
pz @(LeftDef (1 % 4) Id) (Left 20.4)
PresentT (102 % 5)
>>>
pz @(LeftDef (1 % 4) Id) (Right "aa")
PresentT (1 % 4)
>>>
pz @(LeftDef (PrintT "found right=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Right "xy")
PresentT "found right=xy fst=123"
>>>
pz @(LeftDef (MEmptyT _) Id) (Right 222)
PresentT ()
>>>
pz @(LeftDef (MEmptyT (SG.Sum _)) Id) (Right 222)
PresentT (Sum {getSum = 0})
extract the Left value from an Either
otherwise fail with a message
if there is no Left value then p is passed the Right value and the whole context
>>>
pz @(LeftFail "oops" Id) (Left 20.4)
PresentT 20.4
>>>
pz @(LeftFail "oops" Id) (Right "aa")
FailT "oops"
>>>
pz @(LeftFail (PrintT "found right=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Right "xy")
FailT "found right=xy fst=123"
>>>
pz @(LeftFail (MEmptyT _) Id) (Right 222)
FailT ""
extract the Right value from an Either
if there is no Right value then p is passed the Left value and the whole context
>>>
pz @(RightDef (1 % 4) Id) (Right 20.4)
PresentT (102 % 5)
>>>
pz @(RightDef (1 % 4) Id) (Left "aa")
PresentT (1 % 4)
>>>
pz @(RightDef (PrintT "found left=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Left "xy")
PresentT "found left=xy fst=123"
>>>
pz @(RightDef (MEmptyT _) Id) (Left 222)
PresentT ()
>>>
pz @(RightDef (MEmptyT (SG.Sum _)) Id) (Left 222)
PresentT (Sum {getSum = 0})
extract the Right value from an Either
otherwise fail with a message
if there is no Right value then p is passed the Left value and the whole context
>>>
pz @(RightFail "oops" Id) (Right 20.4)
PresentT 20.4
>>>
pz @(RightFail "oops" Id) (Left "aa")
FailT "oops"
>>>
pz @(RightFail (PrintT "found left=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Left "xy")
FailT "found left=xy fst=123"
>>>
pz @(RightFail (MEmptyT _) Id) (Left 222)
FailT ""
data EitherBool b p q Source #
Convenient method to convert a 'p' or '\q' to a Either
based on a predicate '\b\'
if 'b' then Right 'p' else Left '\q\'
>>>
pz @(EitherBool (Fst Id > 4) (Snd Id >> Fst Id) (Snd Id >> Snd Id)) (24,(-1,999))
PresentT (Right 999)
>>>
pz @(EitherBool (Fst Id > 4) (Fst (Snd Id)) (Snd (Snd Id))) (1,(-1,999))
PresentT (Left (-1))
Instances
(Show (PP p a), P p a, Show (PP q a), P q a, P b a, PP b a ~ Bool) => P (EitherBool b p q :: Type) a Source # | |
Defined in Predicate.Prelude type PP (EitherBool b p q) a :: Type Source # eval :: MonadEval m => Proxy (EitherBool b p q) -> POpts -> a -> m (TT (PP (EitherBool b p q) a)) Source # | |
type PP (EitherBool b p q :: Type) a Source # | |
Defined in Predicate.Prelude |
semigroup / monoid expressions
similar to <>
>>>
pz @(Fst Id <> Snd Id) ("abc","def")
PresentT "abcdef"
>>>
pz @("abcd" <> "ef" <> Id) "ghi"
PresentT "abcdefghi"
>>>
pz @("abcd" <> "ef" <> Id) "ghi"
PresentT "abcdefghi"
>>>
pz @(Wrap (SG.Sum _) Id <> FromInteger _ 10) 13
PresentT (Sum {getSum = 23})
>>>
pz @(Wrap (SG.Product _) Id <> FromInteger _ 10) 13
PresentT (Product {getProduct = 130})
>>>
pz @('(FromInteger _ 10,"def") <> Id) (SG.Sum 12, "_XYZ")
PresentT (Sum {getSum = 22},"def_XYZ")
>>>
pz @(SapA' (SG.Max _)) (10,12)
PresentT (Max {getMax = 12})
>>>
pz @(SapA' (SG.Sum _)) (10,12)
PresentT (Sum {getSum = 22})
similar to mconcat
>>>
pz @(MConcat Id) [SG.Sum 44, SG.Sum 12, SG.Sum 3]
PresentT (Sum {getSum = 59})
similar to stimes
>>>
pz @(STimes 4 Id) (SG.Sum 3)
PresentT (Sum {getSum = 12})
>>>
pz @(STimes 4 Id) "ab"
PresentT "abababab"
similar to mempty
>>>
pz @(MEmptyT (SG.Sum Int)) ()
PresentT (Sum {getSum = 0})
no Monoid for Maybe a unless a is also a monoid but can use empty!
lift mempty over a Functor
>>>
pz @(MEmpty2 (SG.Product Int)) [Identity (-13), Identity 4, Identity 99]
PresentT [Product {getProduct = 1},Product {getProduct = 1},Product {getProduct = 1}]
indexing expressions
data Ix (n :: Nat) def Source #
similar to !!
>>>
pz @(Ix 4 "not found") ["abc","D","eF","","G"]
PresentT "G"
>>>
pz @(Ix 40 "not found") ["abc","D","eF","","G"]
PresentT "not found"
>>>
pz @(IxL Id 2 "notfound") ["abc","D","eF","","G"]
PresentT "eF"
>>>
pz @(IxL Id 20 "notfound") ["abc","D","eF","","G"]
PresentT "notfound"
>>>
pz @(Id !! 2) ["abc","D","eF","","G"]
PresentT "eF"
>>>
pz @(Id !! 20) ["abc","D","eF","","G"]
FailT "(!!) index not found"
>>>
import qualified Data.Map.Strict as M
>>>
pz @(Id !! "eF") (M.fromList (flip zip [0..] ["abc","D","eF","","G"]))
PresentT 2
>>>
pz @(Lookup Id 2) ["abc","D","eF","","G"]
PresentT (Just "eF")
>>>
pz @(Lookup Id 20) ["abc","D","eF","","G"]
PresentT Nothing
>>>
pl @((Id !!? Char1 "d") > MkJust 99 || Length Id <= 3) (M.fromList $ zip "abcd" [1..])
False (False || False | (Just 4 > Just 99) || (4 <= 3)) FalseT
>>>
pz @((Id !!? Char1 "d") > MkJust 2 || Length Id <= 3) (M.fromList $ zip "abcd" [1..])
TrueT
data LookupDef' v w p q Source #
Instances
P (LookupDefT' v w p q) x => P (LookupDef' v w p q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (LookupDef' v w p q) x :: Type Source # eval :: MonadEval m => Proxy (LookupDef' v w p q) -> POpts -> x -> m (TT (PP (LookupDef' v w p q) x)) Source # | |
type PP (LookupDef' v w p q :: Type) x Source # | |
Defined in Predicate.Prelude |
data LookupFail msg v w Source #
Instances
P (LookupFailT msg v w) x => P (LookupFail msg v w :: Type) x Source # | |
Defined in Predicate.Prelude type PP (LookupFail msg v w) x :: Type Source # eval :: MonadEval m => Proxy (LookupFail msg v w) -> POpts -> x -> m (TT (PP (LookupFail msg v w) x)) Source # | |
type PP (LookupFail msg v w :: Type) x Source # | |
Defined in Predicate.Prelude |
data LookupFail' msg v w q Source #
Instances
P (LookupFailT' msg v w q) x => P (LookupFail' msg v w q :: Type) x Source # | |
Defined in Predicate.Prelude type PP (LookupFail' msg v w q) x :: Type Source # eval :: MonadEval m => Proxy (LookupFail' msg v w q) -> POpts -> x -> m (TT (PP (LookupFail' msg v w q) x)) Source # | |
type PP (LookupFail' msg v w q :: Type) x Source # | |
Defined in Predicate.Prelude |
cons / uncons expressions
similar to cons
>>>
pz @(Fst Id :+ Snd Id) (99,[1,2,3,4])
PresentT [99,1,2,3,4]
>>>
pz @(Snd Id :+ Fst Id) ([],5)
PresentT [5]
>>>
pz @(123 :+ EmptyList _) "somestuff"
PresentT [123]
similar to snoc
>>>
pz @(Snd Id +: Fst Id) (99,[1,2,3,4])
PresentT [1,2,3,4,99]
>>>
pz @(Fst Id +: Snd Id) ([],5)
PresentT [5]
>>>
pz @(EmptyT [] Id +: 5) 5
PresentT [5]
similar to (++)
>>>
pz @(Fst Id ++ Snd Id) ([9,10,11],[1,2,3,4])
PresentT [9,10,11,1,2,3,4]
>>>
pz @(Snd Id ++ Fst Id) ([],[5])
PresentT [5]
>>>
pz @(Char1 "xyz" :+ W "ab" ++ W "cdefg") ()
PresentT "xabcdefg"
>>>
pz @([1,2,3] ++ EmptyList _) "somestuff"
PresentT [1,2,3]
>>>
pz @Uncons [1,2,3,4]
PresentT (Just (1,[2,3,4]))
>>>
pz @Uncons []
PresentT Nothing
>>>
pz @Uncons (Seq.fromList "abc")
PresentT (Just ('a',fromList "bc"))
>>>
pz @Uncons ("xyz" :: T.Text)
PresentT (Just ('x',"yz"))
>>>
pz @Unsnoc [1,2,3,4]
PresentT (Just ([1,2,3],4))
>>>
pz @Unsnoc []
PresentT Nothing
>>>
pz @Unsnoc ("xyz" :: T.Text)
PresentT (Just ("xy",'z'))
takes the head of a list like container
>>>
pz @(Head Id) "abcd"
PresentT 'a'
>>>
pz @(Head Id) []
FailT "Head(empty)"
takes the tail of a list like container
>>>
pz @(Tail Id) "abcd"
PresentT "bcd"
>>>
pz @(Tail Id) []
FailT "Tail(empty)"
takes the init of a list like container
>>>
pz @(Init Id) "abcd"
PresentT "abc"
>>>
pz @(Init Id) (T.pack "abcd")
PresentT "abc"
>>>
pz @(Init Id) []
FailT "Init(empty)"
takes the last of a list like container
>>>
pz @(Last Id) "abcd"
PresentT 'd'
>>>
pz @(Last Id) []
FailT "Last(empty)"
takes the head or default of a list-like object
see ConsT
for other supported types eg Seq
>>>
pz @(HeadDef 444 Id) []
PresentT 444
>>>
pz @(HeadDef 444 Id) [1..5]
PresentT 1
>>>
pz @(HeadDef 444 Id) [1..5]
PresentT 1
>>>
pz @(HeadDef (Char1 "w") Id) (Seq.fromList "abcdef")
PresentT 'a'
>>>
pz @(HeadDef (Char1 "w") Id) Seq.empty
PresentT 'w'
>>>
:set -XFlexibleContexts
>>>
pz @(HeadDef (MEmptyT _) Id) ([] :: [SG.Sum Int])
PresentT (Sum {getSum = 0})
>>>
pz @(HeadDef (MEmptyT String) '[ "abc","def","asdfadf" ]) ()
PresentT "abc"
>>>
pz @(HeadDef (MEmptyT _) (Snd Id)) (123,[ "abc","def","asdfadf" ])
PresentT "abc"
>>>
pz @(HeadDef (MEmptyT _) (Snd Id)) (123,[])
PresentT ()
takes the head of a list or fail
see ConsT
for other supported types eg Seq
>>>
pz @(HeadFail "dude" Id) [ "abc","def","asdfadf" ]
PresentT "abc"
>>>
pz @(HeadFail "empty list" Id) []
FailT "empty list"
these expressions
data PartitionThese Source #
similar to partitionThese
. returns a 3-tuple with the results so use Fst
Snd
Thd
to extract
>>>
pz @PartitionThese [This 'a', That 2, This 'c', These 'z' 1, That 4, These 'a' 2, That 99]
PresentT ("ac",[2,4,99],[('z',1),('a',2)])
Instances
(Show a, Show b) => P PartitionThese [These a b] Source # | |
Defined in Predicate.Prelude | |
type PP PartitionThese [These a b] Source # | |
Defined in Predicate.Prelude |
This
constructor
>>>
pz @(MkThis _ Id) 44
PresentT (This 44)
>>>
pz @(Proxy Int >> MkThis' Unproxy 10) []
PresentT (This 10)
That
constructor
>>>
pz @(MkThat _ Id) 44
PresentT (That 44)
These
constructor
>>>
pz @(MkThese (Fst Id) (Snd Id)) (44,'x')
PresentT (These 44 'x')
extract the This value from an These
otherwise use the default value
if there is no This value then p is passed the whole context only
>>>
pz @(ThisDef (1 % 4) Id) (This 20.4)
PresentT (102 % 5)
>>>
pz @(ThisDef (1 % 4) Id) (That "aa")
PresentT (1 % 4)
>>>
pz @(ThisDef (1 % 4) Id) (These 2.3 "aa")
PresentT (1 % 4)
>>>
pz @(ThisDef (PrintT "found %s fst=%d" '(ShowP (Snd Id), Fst Id)) (Snd Id)) (123,That "xy")
PresentT "found That \"xy\" fst=123"
>>>
pz @(ThisDef (MEmptyT _) Id) (That 222)
PresentT ()
>>>
pz @(ThisDef (MEmptyT (SG.Sum _)) Id) (These 222 'x')
PresentT (Sum {getSum = 0})
extract the This value from a These
otherwise fail with a message
if there is no This value then p is passed the whole context only
>>>
pz @(ThisFail "oops" Id) (This 20.4)
PresentT 20.4
>>>
pz @(ThisFail "oops" Id) (That "aa")
FailT "oops"
>>>
pz @(ThisFail (PrintT "found %s fst=%d" '(ShowP (Snd Id),Fst Id)) (Snd Id)) (123,That "xy")
FailT "found That \"xy\" fst=123"
>>>
pz @(ThisFail (MEmptyT _) Id) (That 222)
FailT ""
extract the That value from an These
otherwise use the default value
if there is no That value then p is passed the whole context only
>>>
pz @(ThatDef (1 % 4) Id) (That 20.4)
PresentT (102 % 5)
>>>
pz @(ThatDef (1 % 4) Id) (This "aa")
PresentT (1 % 4)
>>>
pz @(ThatDef (1 % 4) Id) (These "aa" 2.3)
PresentT (1 % 4)
>>>
pz @(ThatDef (PrintT "found %s fst=%d" '(ShowP (Snd Id), Fst Id)) (Snd Id)) (123,This "xy")
PresentT "found This \"xy\" fst=123"
>>>
pz @(ThatDef (MEmptyT _) Id) (This 222)
PresentT ()
>>>
pz @(ThatDef (MEmptyT (SG.Sum _)) Id) (These 'x' 1120)
PresentT (Sum {getSum = 0})
extract the That value from a These
otherwise fail with a message
if there is no That value then p is passed the whole context only
>>>
pz @(ThatFail "oops" Id) (That 20.4)
PresentT 20.4
>>>
pz @(ThatFail "oops" Id) (This "aa")
FailT "oops"
>>>
pz @(ThatFail (PrintT "found %s fst=%d" '(ShowP (Snd Id),Fst Id)) (Snd Id)) (123,This "xy")
FailT "found This \"xy\" fst=123"
>>>
pz @(ThatFail (MEmptyT _) Id) (This 222)
FailT ""
extract the These value from an These
otherwise use the default value
if there is no These value then p is passed the whole context only
>>>
pz @(TheseDef '(1 % 4,"zz") Id) (These 20.4 "x")
PresentT (102 % 5,"x")
>>>
pz @(TheseDef '(1 % 4,"zz") Id) (This 20.4)
PresentT (1 % 4,"zz")
>>>
pz @(TheseDef '(1 % 4,"zz") Id) (That "x")
PresentT (1 % 4,"zz")
>>>
pz @(TheseDef '(PrintT "found %s fst=%d" '(ShowP (Snd Id), Fst Id),999) (Snd Id)) (123,This "xy")
PresentT ("found This \"xy\" fst=123",999)
>>>
pz @(TheseDef (MEmptyT (SG.Sum _, String)) Id) (This 222)
PresentT (Sum {getSum = 0},"")
>>>
pz @(TheseDef (MEmptyT _) Id) (These (222 :: SG.Sum Int) "aa")
PresentT (Sum {getSum = 222},"aa")
extract the These value from a These
otherwise fail with a message
if there is no These value then p is passed the whole context only
>>>
pz @(TheseFail "oops" Id) (These "abc" 20.4)
PresentT ("abc",20.4)
>>>
pz @(TheseFail "oops" Id) (That "aa")
FailT "oops"
>>>
pz @(TheseFail (PrintT "found %s fst=%d" '(ShowP (Snd Id),Fst Id)) (Snd Id)) (123,That "xy")
FailT "found That \"xy\" fst=123"
>>>
pz @(TheseFail (MEmptyT _) Id) (That 222)
FailT ""
similar to these
>>>
pz @(TheseIn Id Len (Fst Id + Length (Snd Id))) (This 13)
PresentT 13
>>>
pz @(TheseIn Id Len (Fst Id + Length (Snd Id))) (That "this is a long string")
PresentT 21
>>>
pz @(TheseIn Id Len (Fst Id + Length (Snd Id))) (These 20 "somedata")
PresentT 28
>>>
pz @(TheseIn (MkLeft _ Id) (MkRight _ Id) (If (Fst Id > Length (Snd Id)) (MkLeft _ (Fst Id)) (MkRight _ (Snd Id)))) (That "this is a long string")
PresentT (Right "this is a long string")
>>>
pz @(TheseIn (MkLeft _ Id) (MkRight _ Id) (If (Fst Id > Length (Snd Id)) (MkLeft _ (Fst Id)) (MkRight _ (Snd Id)))) (These 1 "this is a long string")
PresentT (Right "this is a long string")
>>>
pz @(TheseIn (MkLeft _ Id) (MkRight _ Id) (If (Fst Id > Length (Snd Id)) (MkLeft _ (Fst Id)) (MkRight _ (Snd Id)))) (These 100 "this is a long string")
PresentT (Left 100)
similar to mergeTheseWith
but additionally provides 'p', '\q' and 'r' the original input as the first element in the tuple
>>>
pz @(TheseX ((Fst (Fst Id) + Snd Id) >> ShowP Id) (ShowP Id) (Snd (Snd Id)) (Snd Id)) (9,This 123)
PresentT "132"
>>>
pz @(TheseX '(Snd Id,"fromthis") '(Negate 99,Snd Id) (Snd Id) Id) (This 123)
PresentT (123,"fromthis")
>>>
pz @(TheseX '(Snd Id,"fromthis") '(Negate 99,Snd Id) (Snd Id) Id) (That "fromthat")
PresentT (-99,"fromthat")
>>>
pz @(TheseX '(Snd Id,"fromthis") '(Negate 99,Snd Id) (Snd Id) Id) (These 123 "fromthese")
PresentT (123,"fromthese")
fold / unfold expressions
similar to scanl
>>>
pz @(Scanl (Snd Id :+ Fst Id) (Fst Id) (Snd Id)) ([99],[1..5])
PresentT [[99],[1,99],[2,1,99],[3,2,1,99],[4,3,2,1,99],[5,4,3,2,1,99]]
>>>
pz @(ScanN 4 Id (Succ Id)) 'c'
PresentT "cdefg"
>>>
pz @(FoldN 4 Id (Succ Id)) 'c'
PresentT 'g'
>>>
pz @(Dup >> ScanN 4 Id (Pred Id *** Succ Id)) 'g'
PresentT [('g','g'),('f','h'),('e','i'),('d','j'),('c','k')]
similar to unfoldr
>>>
pz @(Unfoldr (MaybeBool (Not Null) (SplitAt 2 Id)) Id) [1..5]
PresentT [[1,2],[3,4],[5]]
like iterate
but for a fixed number of elements
>>>
pz @(IterateN 4 (Succ Id)) 4
PresentT [4,5,6,7]
>>>
pz @('(0,1) >> IterateN 20 '(Snd Id, Fst Id + Snd Id) >> Map (Fst Id) Id) "sdf"
PresentT [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181]
data IterateUntil p f Source #
Instances
P (IterateUntilT p f) x => P (IterateUntil p f :: Type) x Source # | |
Defined in Predicate.Prelude type PP (IterateUntil p f) x :: Type Source # eval :: MonadEval m => Proxy (IterateUntil p f) -> POpts -> x -> m (TT (PP (IterateUntil p f) x)) Source # | |
type PP (IterateUntil p f :: Type) x Source # | |
Defined in Predicate.Prelude |
data IterateWhile p f Source #
Instances
P (IterateWhileT p f) x => P (IterateWhile p f :: Type) x Source # | |
Defined in Predicate.Prelude type PP (IterateWhile p f) x :: Type Source # eval :: MonadEval m => Proxy (IterateWhile p f) -> POpts -> x -> m (TT (PP (IterateWhile p f) x)) Source # | |
type PP (IterateWhile p f :: Type) x Source # | |
Defined in Predicate.Prelude |
data IterateNWhile n p f Source #
Instances
P (IterateNWhileT n p f) x => P (IterateNWhile n p f :: Type) x Source # | |
Defined in Predicate.Prelude type PP (IterateNWhile n p f) x :: Type Source # eval :: MonadEval m => Proxy (IterateNWhile n p f) -> POpts -> x -> m (TT (PP (IterateNWhile n p f) x)) Source # | |
type PP (IterateNWhile n p f :: Type) x Source # | |
Defined in Predicate.Prelude |
data IterateNUntil n p f Source #
Instances
P (IterateNUntilT n p f) x => P (IterateNUntil n p f :: Type) x Source # | |
Defined in Predicate.Prelude type PP (IterateNUntil n p f) x :: Type Source # eval :: MonadEval m => Proxy (IterateNUntil n p f) -> POpts -> x -> m (TT (PP (IterateNUntil n p f) x)) Source # | |
type PP (IterateNUntil n p f :: Type) x Source # | |
Defined in Predicate.Prelude |
failure expressions
Fails the computation with a message
>>>
pz @(Failt Int (PrintF "value=%03d" Id)) 99
FailT "value=099"
>>>
pz @(FailS (PrintT "value=%03d string=%s" Id)) (99,"somedata")
FailT "value=099 string=somedata"
catch a failure
>>>
pz @(Catch (Succ Id) (Fst Id >> Second (ShowP Id) >> PrintT "%s %s" Id >> 'LT)) GT
PresentT LT
>>>
pz @(Catch' (Succ Id) (Second (ShowP Id) >> PrintT "%s %s" Id)) GT
FailT "Succ IO e=Prelude.Enum.Ordering.succ: bad argument GT"
>>>
pz @(Catch' (Succ Id) (Second (ShowP Id) >> PrintT "%s %s" Id)) LT
PresentT EQ
>>>
pz @(Len > 1 && Catch (Id !! 3 == 66) 'False) [1,2]
FalseT
more flexible: takes a (String,x) and a proxy so we can still call 'False 'True now takes the FailT string and x so you can print more detail if you want need the proxy so we can fail without having to explicitly specify a type
zip expressions
similar to align
thats pads with This
or That
if one list is shorter than the other
the key is that all information about both lists are preserved
>>>
pz @(ZipThese (Fst Id) (Snd Id)) ("aBc", [1..5])
PresentT [These 'a' 1,These 'B' 2,These 'c' 3,That 4,That 5]
>>>
pz @(ZipThese (Fst Id) (Snd Id)) ("aBcDeF", [1..3])
PresentT [These 'a' 1,These 'B' 2,These 'c' 3,This 'D',This 'e',This 'F']
>>>
pz @(ZipThese Id Reverse) "aBcDeF"
PresentT [These 'a' 'F',These 'B' 'e',These 'c' 'D',These 'D' 'c',These 'e' 'B',These 'F' 'a']
>>>
pz @(ZipThese Id '[]) "aBcDeF"
PresentT [This 'a',This 'B',This 'c',This 'D',This 'e',This 'F']
>>>
pz @(ZipThese '[] Id) "aBcDeF"
PresentT [That 'a',That 'B',That 'c',That 'D',That 'e',That 'F']
>>>
pz @(ZipThese '[] '[]) "aBcDeF"
PresentT []
zip two lists padding the left hand side if needed
>>>
pl @(ZipL 99 '[1,2,3] "abc") ()
Present [(1,'a'),(2,'b'),(3,'c')] (ZipL [(1,'a'),(2,'b'),(3,'c')] | p=[1,2,3] | q="abc") PresentT [(1,'a'),(2,'b'),(3,'c')]
>>>
pl @(ZipL 99 '[1,2] "abc") ()
Present [(1,'a'),(2,'b'),(99,'c')] (ZipL [(1,'a'),(2,'b'),(99,'c')] | p=[1,2] | q="abc") PresentT [(1,'a'),(2,'b'),(99,'c')]
>>>
pl @(ZipL 99 '[1] "abc") ()
Present [(1,'a'),(99,'b'),(99,'c')] (ZipL [(1,'a'),(99,'b'),(99,'c')] | p=[1] | q="abc") PresentT [(1,'a'),(99,'b'),(99,'c')]
>>>
pl @(ZipL 99 '[1,2,3] "ab") ()
Error ZipL(3,2) rhs would be truncated (ZipL(3,2) | p=[1,2,3] | q="ab") FailT "ZipL(3,2) rhs would be truncated"
zip two lists padding the right hand side if needed
>>>
pl @(ZipR (Char1 "Z") '[1,2,3] "abc") ()
Present [(1,'a'),(2,'b'),(3,'c')] (ZipR [(1,'a'),(2,'b'),(3,'c')] | p=[1,2,3] | q="abc") PresentT [(1,'a'),(2,'b'),(3,'c')]
>>>
pl @(ZipR (Char1 "Z") '[1,2,3] "ab") ()
Present [(1,'a'),(2,'b'),(3,'Z')] (ZipR [(1,'a'),(2,'b'),(3,'Z')] | p=[1,2,3] | q="ab") PresentT [(1,'a'),(2,'b'),(3,'Z')]
>>>
pl @(ZipR (Char1 "Z") '[1,2,3] "a") ()
Present [(1,'a'),(2,'Z'),(3,'Z')] (ZipR [(1,'a'),(2,'Z'),(3,'Z')] | p=[1,2,3] | q="a") PresentT [(1,'a'),(2,'Z'),(3,'Z')]
>>>
pl @(ZipR (Char1 "Z") '[1,2] "abc") ()
Error ZipR(2,3) rhs would be truncated (ZipR(2,3) | p=[1,2] | q="abc") FailT "ZipR(2,3) rhs would be truncated"
zip two lists with the same length
>>>
pl @(Zip '[1,2,3] "abc") ()
Present [(1,'a'),(2,'b'),(3,'c')] (Zip [(1,'a'),(2,'b'),(3,'c')] | p=[1,2,3] | q="abc") PresentT [(1,'a'),(2,'b'),(3,'c')]
>>>
pl @(Zip '[1,2,3] "ab") ()
Error Zip(3,2) length mismatch (Zip(3,2) | p=[1,2,3] | q="ab") FailT "Zip(3,2) length mismatch"
>>>
pl @(Zip '[1,2] "abc") ()
Error Zip(2,3) length mismatch (Zip(2,3) | p=[1,2] | q="abc") FailT "Zip(2,3) length mismatch"
unzip
equivalent
>>>
pz @Unzip (zip [1..5] "abcd")
PresentT ([1,2,3,4],"abcd")
unzip3
equivalent
>>>
pz @Unzip3 (zip3 [1..5] "abcd" (cycle [True,False]))
PresentT ([1,2,3,4],"abcd",[True,False,True,False])
conditional expressions
if p then run q else run r
>>>
pz @(If (Gt 4) "greater than 4" "less than or equal to 4" ) 10
PresentT "greater than 4"
>>>
pz @(If (Gt 4) "greater than 4" "less than or equal to 4") 0
PresentT "less than or equal to 4"
>>>
pz @(If (Snd Id == "a") '("xxx",Fst Id + 13) (If (Snd Id == "b") '("yyy",Fst Id + 7) (Failt _ "oops"))) (99,"b")
PresentT ("yyy",106)
data Case (e :: k0) (ps :: [k]) (qs :: [k1]) (r :: k2) Source #
data GuardsQuick (prt :: k) (ps :: [k1]) Source #
Instances
P (GuardsQuickT prt ps) x => P (GuardsQuick prt ps :: Type) x Source # | |
Defined in Predicate.Prelude type PP (GuardsQuick prt ps) x :: Type Source # eval :: MonadEval m => Proxy (GuardsQuick prt ps) -> POpts -> x -> m (TT (PP (GuardsQuick prt ps) x)) Source # | |
type PP (GuardsQuick prt ps :: Type) x Source # | |
Defined in Predicate.Prelude |
'p' is the predicate and on failure of the predicate runs 'prt'
>>>
pz @(Guard "expected > 3" (Gt 3)) 17
PresentT 17
>>>
pz @(Guard "expected > 3" (Gt 3)) 1
FailT "expected > 3"
>>>
pz @(Guard (PrintF "%d not > 3" Id) (Gt 3)) (-99)
FailT "-99 not > 3"
data GuardSimple p Source #
similar to Guard
but uses the root message of the False predicate case as the failure message
most uses of GuardSimple can be replaced by a boolean predicate unless you require a failure message instead of true/false
>>>
pz @(GuardSimple (Luhn Id)) [1..4]
FailT "(Luhn map=[4,6,2,2] sum=14 ret=4 | [1,2,3,4])"
>>>
pl @(Luhn Id) [1..4]
False (Luhn map=[4,6,2,2] sum=14 ret=4 | [1,2,3,4]) FalseT
>>>
pz @(GuardSimple (Luhn Id)) [1,2,3,0]
PresentT [1,2,3,0]
>>>
pz @(GuardSimple (Len > 30)) [1,2,3,0]
FailT "(4 > 30)"
Instances
(Show a, P p a, PP p a ~ Bool) => P (GuardSimple p :: Type) a Source # | |
Defined in Predicate.Prelude type PP (GuardSimple p) a :: Type Source # eval :: MonadEval m => Proxy (GuardSimple p) -> POpts -> a -> m (TT (PP (GuardSimple p) a)) Source # | |
type PP (GuardSimple p :: Type) a Source # | |
Defined in Predicate.Prelude |
data GuardsN prt (n :: Nat) p Source #
leverages RepeatT
for repeating predicates (passthrough method)
>>>
pz @(GuardsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (Between 0 255 Id)) [121,33,7,256]
FailT "id=3 must be between 0 and 255, found 256"
>>>
pz @(GuardsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (Between 0 255 Id)) [121,33,7,44]
PresentT [121,33,7,44]
data GuardsDetail prt (ps :: [(k0, k1)]) Source #
Instances
P (GuardsDetailT prt ps) x => P (GuardsDetail prt ps :: Type) x Source # | |
Defined in Predicate.Prelude type PP (GuardsDetail prt ps) x :: Type Source # eval :: MonadEval m => Proxy (GuardsDetail prt ps) -> POpts -> x -> m (TT (PP (GuardsDetail prt ps) x)) Source # | |
type PP (GuardsDetail prt ps :: Type) x Source # | |
Defined in Predicate.Prelude |
data Bools (ps :: [(k, k1)]) Source #
boolean guard which checks a given a list of predicates against the list of values
prefer Bools
as BoolsQuick
doesnt give much added value: passes in the index and the value to prt but you already have the index in the message
pulls the top message from the tree if a predicate is false
>>>
pl @(Bools '[ '(W "hh",Between 0 23 Id), '(W "mm",Between 0 59 Id), '(PrintT "<<<%d %d>>>" Id,Between 0 59 Id) ] ) [12,93,14]
False (Bool(1) [mm] (93 <= 59)) FalseT
>>>
pl @(Bools '[ '(W "hh",Between 0 23 Id), '(W "mm",Between 0 59 Id), '(PrintT "<<<%d %d>>>" Id,Between 0 59 Id) ] ) [12,13,94]
False (Bool(2) [<<<2 94>>>] (94 <= 59)) FalseT
>>>
pl @(Bools '[ '(W "hh",Between 0 23 Id), '(W "mm",Between 0 59 Id), '(PrintT "<<<%d %d>>>" Id,Between 0 59 Id) ] ) [12,13,14]
True (Bools) TrueT
>>>
pl @(BoolsQuick "abc" '[Between 0 23 Id, Between 0 59 Id, Between 0 59 Id]) [12,13,14]
True (Bools) TrueT
>>>
pl @(BoolsQuick (PrintT "id=%d val=%d" Id) '[Between 0 23 Id, Between 0 59 Id, Between 0 59 Id]) [12,13,14]
True (Bools) TrueT
>>>
pl @(BoolsQuick (PrintT "id=%d val=%d" Id) '[Between 0 23 Id, Between 0 59 Id, Between 0 59 Id]) [12,13,99]
False (Bool(2) [id=2 val=99] (99 <= 59)) FalseT
>>>
pl @(Bools '[ '("hours",Between 0 23 Id), '("minutes",Between 0 59 Id), '("seconds",Between 0 59 Id) ] ) [12,13,14]
True (Bools) TrueT
>>>
pl @(Bools '[ '("hours",Between 0 23 Id), '("minutes",Between 0 59 Id), '("seconds",Between 0 59 Id) ] ) [12,60,14]
False (Bool(1) [minutes] (60 <= 59)) FalseT
>>>
pl @(Bools '[ '("hours",Between 0 23 Id), '("minutes",Between 0 59 Id), '("seconds",Between 0 59 Id) ] ) [12,60,14,20]
False (Bools:invalid length(4) expected 3) FalseT
data BoolsQuick (prt :: k) (ps :: [k1]) Source #
Instances
(PP (Bools (ToGuardsT prt ps)) x ~ Bool, P (BoolsQuickT prt ps) x) => P (BoolsQuick prt ps :: Type) x Source # | |
Defined in Predicate.Prelude type PP (BoolsQuick prt ps) x :: Type Source # eval :: MonadEval m => Proxy (BoolsQuick prt ps) -> POpts -> x -> m (TT (PP (BoolsQuick prt ps) x)) Source # | |
type PP (BoolsQuick prt ps :: Type) x Source # | |
Defined in Predicate.Prelude |
data BoolsN prt (n :: Nat) (p :: k1) Source #
leverages RepeatT
for repeating predicates (passthrough method)
>>>
pl @(BoolsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (Between 0 255 Id)) [121,33,7,256]
False (Bool(3) [id=3 must be between 0 and 255, found 256] (256 <= 255)) FalseT
>>>
pl @(BoolsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (Between 0 255 Id)) [121,33,7,44]
True (Bools) TrueT
IO expressions
similar to readFile
>>>
pz @(ReadFile "LICENSE" >> 'Just Id >> Len > 0) ()
TrueT
>>>
pz @(FileExists "xyzzy") ()
FalseT
data FileExists p Source #
Instances
P (FileExistsT p) x => P (FileExists p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (FileExists p) x :: Type Source # eval :: MonadEval m => Proxy (FileExists p) -> POpts -> x -> m (TT (PP (FileExists p) x)) Source # | |
type PP (FileExists p :: Type) x Source # | |
Defined in Predicate.Prelude |
does the directory exists
>>>
pz @(DirExists ".") ()
TrueT
read an environment variable
>>>
pz @(ReadEnv "PATH" >> 'Just Id >> 'True) ()
TrueT
data ReadEnvAll Source #
read all the environment variables as key value pairs
Instances
P ReadEnvAll a Source # | |
Defined in Predicate.Prelude type PP ReadEnvAll a :: Type Source # eval :: MonadEval m => Proxy ReadEnvAll -> POpts -> a -> m (TT (PP ReadEnvAll a)) Source # | |
type PP ReadEnvAll a Source # | |
Defined in Predicate.Prelude |
get the current time using UTCTime
get the current time using ZonedTime
data AppendFile (s :: Symbol) p Source #
append to a file
Instances
P (AppendFileT s p) x => P (AppendFile s p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (AppendFile s p) x :: Type Source # eval :: MonadEval m => Proxy (AppendFile s p) -> POpts -> x -> m (TT (PP (AppendFile s p) x)) Source # | |
type PP (AppendFile s p :: Type) x Source # | |
Defined in Predicate.Prelude |
data WriteFile (s :: Symbol) p Source #
write to file, without overwriting
data WriteFile' (s :: Symbol) p Source #
write to file, overwriting if needed
Instances
P (WriteFileT' s p) x => P (WriteFile' s p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (WriteFile' s p) x :: Type Source # eval :: MonadEval m => Proxy (WriteFile' s p) -> POpts -> x -> m (TT (PP (WriteFile' s p) x)) Source # | |
type PP (WriteFile' s p :: Type) x Source # | |
Defined in Predicate.Prelude |
write a string value to stdout
write a string value to stderr
read a value from stdin
type ReadIO (t :: Type) = ReadIO' t "Enter value" Source #
read in a value of a given type from stdin with a prompt: similar to readIO
string expressions
converts a string IsText
value to lower case
>>>
pz @ToLower "HeLlO wOrld!"
PresentT "hello world!"
converts a string IsText
value to upper case
>>>
pz @ToUpper "HeLlO wOrld!"
PresentT "HELLO WORLD!"
converts a string IsText
value to title case
>>>
pz @ToTitle "HeLlO wOrld!"
PresentT "Hello world!"
>>>
data Color = Red | White | Blue | Green | Black deriving (Show,Eq,Enum,Bounded,Read)
>>>
pz @(ToTitle >> ReadP Color Id) "red"
PresentT Red
very simple conversion to a string
data FromString (t :: Type) p Source #
Instances
P (FromStringPT t p) x => P (FromString t p :: Type) x Source # | |
Defined in Predicate.Prelude type PP (FromString t p) x :: Type Source # eval :: MonadEval m => Proxy (FromString t p) -> POpts -> x -> m (TT (PP (FromString t p) x)) Source # | |
type PP (FromString t p :: Type) x Source # | |
Defined in Predicate.Prelude |
data FromString' t s Source #
fromString
function where you need to provide the type 't' of the result
>>>
:set -XFlexibleContexts
>>>
pz @(FromString (Identity _) Id) "abc"
PresentT (Identity "abc")
>>>
pz @(FromString (Seq.Seq Char) Id) "abc"
PresentT (fromList "abc")
Instances
(P s a, PP s a ~ String, Show (PP t a), IsString (PP t a)) => P (FromString' t s :: Type) a Source # | |
Defined in Predicate.Prelude type PP (FromString' t s) a :: Type Source # eval :: MonadEval m => Proxy (FromString' t s) -> POpts -> a -> m (TT (PP (FromString' t s) a)) Source # | |
type PP (FromString' t s :: Type) a Source # | |
Defined in Predicate.Prelude |
print expressions
uses PrintF to format output for a single value
>>>
pz @(PrintF "value=%03d" Id) 12
PresentT "value=012"
>>>
pz @(PrintF "%s" (Fst Id)) ("abc",'x')
PresentT "abc"
>>>
pz @(PrintF "%d" (Fst Id)) ("abc",'x')
FailT "PrintF (IO e=printf: bad formatting char 'd')"
data PrintL (n :: Nat) s p Source #
print for lists -- use PrintT
as it is safer than PrintL
>>>
pl @(PrintL 4 "%s %s %s %s" '[W "xyz", ShowP (Fst Id), ShowP (Snd Id), Thd Id]) (123,'x',"ab")
Present "xyz 123 'x' ab" (PrintL(4) [xyz 123 'x' ab] | s=%s %s %s %s) PresentT "xyz 123 'x' ab"
>>>
pz @(PrintL 1 "%05d" '[Id]) 123 -- tick is required for a one element list (use 'PrintF')
PresentT "00123"
>>>
pz @(PrintL 2 "%d %05d" [Fst Id,Snd Id]) (29,123)
PresentT "29 00123"
>>>
pl @(PrintL 3 "first=%d second=%d third=%d" Id) [10,11,12]
Present "first=10 second=11 third=12" (PrintL(3) [first=10 second=11 third=12] | s=first=%d second=%d third=%d) PresentT "first=10 second=11 third=12"
>>>
pl @(PrintL 2 "first=%d second=%d third=%d" Id) [10,11,12]
Error PrintL(2) arg count=3 (PrintL(2) wrong length 3) FailT "PrintL(2) arg count=3"
>>>
pl @(PrintL 4 "first=%d second=%d third=%d" Id) [10,11,12]
Error PrintL(4) arg count=3 (PrintL(4) wrong length 3) FailT "PrintL(4) arg count=3"
print for flat n-tuples of size two or larger
>>>
pl @(PrintT "%d %s %s %s" '(Fst Id, Snd Id, Snd Id,Snd Id)) (10,"Asdf")
Present "10 Asdf Asdf Asdf" (PrintT [10 Asdf Asdf Asdf] | s=%d %s %s %s) PresentT "10 Asdf Asdf Asdf"
>>>
pl @(PrintT "%c %d %s" Id) ('x', 10,"Asdf")
Present "x 10 Asdf" (PrintT [x 10 Asdf] | s=%c %d %s) PresentT "x 10 Asdf"
>>>
pz @(PrintT "fst=%s snd=%03d" Id) ("ab",123)
PresentT "fst=ab snd=123"
>>>
pz @(PrintT "fst=%s snd=%03d thd=%s" Id) ("ab",123,"xx")
PresentT "fst=ab snd=123 thd=xx"
>>>
pl @(PrintT "%s %d %c %s" '(W "xyz", Fst Id, Snd Id, Thd Id)) (123,'x',"ab")
Present "xyz 123 x ab" (PrintT [xyz 123 x ab] | s=%s %d %c %s) PresentT "xyz 123 x ab"
>>>
pl @(PrintT "%d %c %s" Id) (123,'x')
Error PrintT(IO e=printf: argument list ended prematurely) (PrintT s=%d %c %s) FailT "PrintT(IO e=printf: argument list ended prematurely)"
>>>
pl @(PrintT "%d %c %s" Id) (123,'x',"abc",11)
Error PrintT(IO e=printf: formatting string ended prematurely) (PrintT s=%d %c %s) FailT "PrintT(IO e=printf: formatting string ended prematurely)"
higher order expressions
data Pure (t :: Type -> Type) p Source #
similar to pure
>>>
pz @(Pure Maybe Id) 4
PresentT (Just 4)
>>>
pz @(Pure [] Id) 4
PresentT [4]
>>>
pz @(Pure (Either String) (Fst Id)) (13,True)
PresentT (Right 13)
data Pure2 (t :: Type -> Type) Source #
lift pure over a Functor
>>>
pz @(Pure2 (Either String)) [1,2,4]
PresentT [Right 1,Right 2,Right 4]
data FoldMap (t :: Type) p Source #
similar to a limited form of foldMap
>>>
pz @(FoldMap (SG.Sum _) Id) [44, 12, 3]
PresentT 59
>>>
pz @(FoldMap (SG.Product _) Id) [44, 12, 3]
PresentT 1584
>>>
type Ands' p = FoldMap SG.All p
>>>
pz @(Ands' Id) [True,False,True,True]
PresentT False
>>>
pz @(Ands' Id) [True,True,True]
PresentT True
>>>
pz @(Ands' Id) []
PresentT True
>>>
type Ors' p = FoldMap SG.Any p
>>>
pz @(Ors' Id) [False,False,False]
PresentT False
>>>
pz @(Ors' Id) []
PresentT False
>>>
pz @(Ors' Id) [False,False,False,True]
PresentT True
>>>
type AllPositive' = FoldMap SG.All (Map Positive Id)
>>>
pz @AllPositive' [3,1,-5,10,2,3]
PresentT False
>>>
type AllNegative' = FoldMap SG.All (Map Negative Id)
>>>
pz @AllNegative' [-1,-5,-10,-2,-3]
PresentT True
>>>
:set -XKindSignatures
>>>
type Max' (t :: Type) = FoldMap (SG.Max t) Id -- requires t be Bounded for monoid instance
>>>
pz @(Max' Int) [10,4,5,12,3,4]
PresentT 12
similar to <$
>>>
pz @(Fst Id <$ Snd Id) ("abc",Just 20)
PresentT (Just "abc")
similar to fmap fst
>>>
pz @FMapFst (Just (13,"Asf"))
PresentT (Just 13)
to make this work we grab the fst or snd out of the Maybe so it is a head or not/ is a tail or not etc! we still have access to the whole original list so we dont lose anything!
similar to fmap snd
>>>
pz @FMapSnd (Just ("asf",13))
PresentT (Just 13)
similar to sequenceA
>>>
pz @Sequence [Just 10, Just 20, Just 30]
PresentT (Just [10,20,30])
>>>
pz @Sequence [Just 10, Just 20, Just 30, Nothing, Just 40]
PresentT Nothing
Instances
(Show (f (t a)), Show (t (f a)), Traversable t, Applicative f) => P Sequence (t (f a)) Source # | |
type PP Sequence (t (f a)) Source # | |
Defined in Predicate.Prelude |
similar to join
>>>
pz @Join (Just (Just 20))
PresentT (Just 20)
>>>
pz @Join ["ab","cd","","ef"]
PresentT "abcdef"
data EmptyT (t :: Type -> Type) p Source #
similar to empty
>>>
pz @(EmptyT Maybe Id) ()
PresentT Nothing
>>>
pz @(EmptyT [] Id) ()
PresentT []
>>>
pz @(EmptyT [] (Char1 "x")) (13,True)
PresentT ""
>>>
pz @(EmptyT (Either String) (Fst Id)) (13,True)
PresentT (Left "")
data p <|> q infixl 3 Source #
similar to <|>
>>>
pz @(Fst Id <|> Snd Id) (Nothing,Just 20)
PresentT (Just 20)
>>>
pz @(Fst Id <|> Snd Id) (Just 10,Just 20)
PresentT (Just 10)
>>>
pz @(Fst Id <|> Snd Id) (Nothing,Nothing)
PresentT Nothing
similar to extract
>>>
pz @Extract (Nothing,Just 20)
PresentT (Just 20)
>>>
pz @Extract (Identity 20)
PresentT 20
similar to duplicate
>>>
pz @Duplicate (20,"abc")
PresentT (20,(20,"abc"))
expression combinators
data (p :: k -> k1) $ (q :: k) infixr 0 Source #
like $
for expressions
>>>
pl @(Fst $ Snd $ Id) ((1,2),(3,4))
Present 3 (Fst 3 | (3,4)) PresentT 3
>>>
pl @((<=) 4 $ Fst $ Snd $ Id) ((1,2),(3,4))
False (4 <= 3) FalseT
data (q :: k) & (p :: k -> k1) infixl 1 Source #
similar to &
>>>
pl @(Id & Fst & Singleton & Length) (13,"xyzw")
Present 1 (Length 1 | [13]) PresentT 1
>>>
pl @(2 & (&&&) "abc") ()
Present ("abc",2) (W'(,)) PresentT ("abc",2)
>>>
pl @(2 & '(,) "abc") ()
Present ("abc",2) ('(,)) PresentT ("abc",2)
>>>
pl @('(,) 4 $ '(,) 7 $ "aa") ()
Present (4,(7,"aa")) ('(,)) PresentT (4,(7,"aa"))
>>>
pl @(Thd $ Snd $ Fst Id) ((1,("W",9,'a')),(3,4))
Present 'a' (Thd 'a' | ("W",9,'a')) PresentT 'a'
processes a type level list predicates running each in sequence: see >>
>>>
pz @(Do [Pred Id, ShowP Id, Id &&& Len]) 9876543
PresentT ("9876542",7)
>>>
pz @(Do '[W 123, W "xyz", Len &&& Id, Pred Id *** Id<>Id]) ()
PresentT (2,"xyzxyz")
data Dot (ps :: [Type -> Type]) (q :: Type) Source #
compose simple functions
>>>
pl @(Dot '[Thd,Snd,Fst] Id) ((1,(2,9,10)),(3,4))
Present 10 (Thd 10 | (2,9,10)) PresentT 10
data RDot (ps :: [Type -> Type]) (q :: Type) Source #
reversed dot
>>>
pl @(RDot '[Fst,Snd,Thd] Id) ((1,(2,9,10)),(3,4))
Present 10 (Thd 10 | (2,9,10)) PresentT 10
>>>
pl @(RDot '[Fst,Snd] Id) (('a',2),(True,"zy"))
Present 2 (Snd 2 | ('a',2)) PresentT 2
This is composition for predicates
>>>
pz @(Fst Id >> Succ (Id !! 0)) ([11,12],'x')
PresentT 12
>>>
pz @(Len *** Succ Id >> ShowP (First (Pred Id))) ([11,12],'x')
PresentT "(1,'y')"
data DoN (n :: Nat) p Source #
leverages Do
for repeating predicates (passthrough method)
same as DoN n p == FoldN n p Id
but more efficient
>>>
pz @(DoN 4 (Succ Id)) 'c'
PresentT 'g'
>>>
pz @(DoN 4 (Id <> " | ")) "abc"
PresentT "abc | | | | "
>>>
pz @(DoN 4 (Id <> "|" <> Id)) "abc"
PresentT "abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc"
function application for expressions: similar to $
pz @(Fst Id $$ Snd Id) ((*16),4) PresentT 64
pz @(Id $$ "def") ("abc"<>) PresentT "abcdef"
flipped function application for expressions: similar to &
pz @(Snd Id $& Fst Id) ((*16),4) PresentT 64
pz @("def" $& Id) ("abc"<>) PresentT "abcdef"
data K (p :: k) (q :: k1) Source #
creates a constant expression ignoring the second argument
>>>
pl @(RDot '[Fst,Snd,Thd,K "xxx"] Id) ((1,(2,9,10)),(3,4))
Present "xxx" (K'xxx) PresentT "xxx"
>>>
pl @(RDot '[Fst,Snd,Thd,K '("abc",Id)] Id) ((1,(2,9,10)),(3,4))
Present ("abc",((1,(2,9,10)),(3,4))) (K'(,)) PresentT ("abc",((1,(2,9,10)),(3,4)))
>>>
pl @(Thd $ Snd $ Fst $ K Id "dud") ((1,("W",9,'a')),(3,4))
Present 'a' (Thd 'a' | ("W",9,'a')) PresentT 'a'
>>>
pl @((Thd $ Snd $ Fst $ K Id "dud") >> Pred Id) ((1,("W",9,'a')),(3,4))
Present '`' ((>>) '`' | {Pred '`' | 'a'}) PresentT '`'
run the expression 'p' but remove the subtrees
just run the effect but skip the value for example for use with Stdout so it doesnt interfere with the 'a' on the rhs unless there is an failure
data Uncurry (p :: Type -> Type -> Type -> Type) q r Source #
uncurry experiment
>>>
pl @(Uncurry Between (ReadP (Day,Day) "(2017-04-11,2018-12-30)") (ReadP Day Id)) "2019-10-12"
False (Uncurry (2019-10-12 <= 2018-12-30)) FalseT
>>>
pl @(Uncurry Between (ReadP (Day,Day) "(2017-04-11,2018-12-30)") (ReadP Day Id)) "2017-10-12"
True (Uncurry (2017-04-11 <= 2017-10-12 <= 2018-12-30)) TrueT
>>>
pl @(Uncurry Between (ReadP (Day,Day) "(2017-04-11,2018-12-30)") (ReadP Day Id)) "2016-10-12"
False (Uncurry (2017-04-11 <= 2016-10-12)) FalseT
parallel expressions
data ParaN (n :: Nat) p Source #
leverages Para
for repeating predicates (passthrough method)
>>>
pz @(ParaN 4 (Succ Id)) [1..4]
PresentT [2,3,4,5]
>>>
pz @(ParaN 4 (Succ Id)) "azwxm"
FailT "Para:invalid length(5) expected 4"
>>>
pz @(ParaN 4 (Succ Id)) "azwx"
PresentT "b{xy"
data Repeat (n :: Nat) p Source #
creates a promoted list of predicates and then evaluates them into a list. see PP instance for '[k]
>>>
pz @(Repeat 4 (Succ Id)) 'c'
PresentT "dddd"
>>>
pz @(Repeat 4 "abc") ()
PresentT ["abc","abc","abc","abc"]
miscellaneous
applies 'p' to the first and second slot of an n-tuple
>>>
pl @(Both Len (Fst Id)) (("abc",[10..17],1,2,3),True)
Present (3,8) (Both) PresentT (3,8)
>>>
pl @(Both (Pred Id) $ Fst Id) ((12,'z',[10..17]),True)
Present (11,'y') (Both) PresentT (11,'y')
>>>
pl @(Both (Succ Id) Id) (4,'a')
Present (5,'b') (Both) PresentT (5,'b')
>>>
pl @(Both Len (Fst Id)) (("abc",[10..17]),True)
Present (3,8) (Both) PresentT (3,8)
>>>
pl @(Both (ReadP Day Id) Id) ("1999-01-01","2001-02-12")
Present (1999-01-01,2001-02-12) (Both) PresentT (1999-01-01,2001-02-12)
a predicate on prime numbers
>>>
pz @(Prime Id) 2
TrueT
>>>
pz @(Map '(Id,Prime Id) Id) [0..12]
PresentT [(0,False),(1,False),(2,True),(3,True),(4,False),(5,True),(6,False),(7,True),(8,False),(9,False),(10,False),(11,True),(12,False)]
get the next prime number
>>>
pz @(PrimeNext Id) 6
PresentT 7
>>>
pz @(IterateN 4 (PrimeNext Id)) 3
PresentT [3,5,7,11]
Luhn predicate check on last digit
>>>
pz @(Luhn Id) [1,2,3,0]
TrueT
>>>
pz @(Luhn Id) [1,2,3,4]
FalseT
>>>
pz @(GuardSimple (Luhn Id)) [15,4,3,1,99]
FailT "(Luhn map=[90,2,3,8,6] sum=109 ret=9 | [15,4,3,1,99])"
>>>
pl @(Luhn Id) [15,4,3,1,99]
False (Luhn map=[90,2,3,8,6] sum=109 ret=9 | [15,4,3,1,99]) FalseT
data Char1 (s :: Symbol) Source #
extracts the first character from a non empty Symbol
>>>
pz @(Char1 "aBc") ()
PresentT 'a'