Safe Haskell | None |
---|---|
Language | Haskell2010 |
- boolean expressions
- regex expressions
- tuple expressions
- character expressions
- datetime expressions
- numeric expressions
- proxy expressions
- read / show expressions
- arrow expressions
- compare expressions
- enum expressions
- wrap / unwrap expressions
- list / foldable expressions
- maybe expressions
- either expressions
- semigroup / monoid expressions
- indexing expressions
- these expressions
- fold / unfold expressions
- failure expressions
- zip expressions
- conditional expressions
- IO expressions
- string expressions
- print expressions
- higher order expressions
- expression combinators
- miscellaneous
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 Not p
- data Ands p
- data Ors p
- type Asc = All (Fst Id <= Snd Id) Pairs
- type Asc' = All (Fst Id < Snd Id) Pairs
- type Desc = All (Fst Id >= Snd Id) Pairs
- type Desc' = All (Fst Id > Snd Id) Pairs
- type Between p q = Between' p q Id
- type (<..>) p q = Between p q
- data Between' p q r
- data All p q
- data Any p q
- type AllPositive = All Positive Id
- type Positive = Gt 0
- type AllNegative = All Negative Id
- type Negative = Lt 0
- type Re p q = Re' '[] p q
- data Re' (rs :: [ROpt]) p q
- type Rescan p q = Rescan' '[] p q
- data Rescan' (rs :: [ROpt]) p q
- type RescanRanges p q = RescanRanges' '[] p q
- data RescanRanges' (rs :: [ROpt]) p q
- type Resplit p q = Resplit' '[] p q
- data Resplit' (rs :: [ROpt]) p q
- type ReplaceAll p q r = ReplaceAll' '[] p q r
- type ReplaceAll' (rs :: [ROpt]) p q r = ReplaceImpl True rs p q r
- type ReplaceOne p q r = ReplaceOne' '[] p q r
- type ReplaceOne' (rs :: [ROpt]) p q r = ReplaceImpl False rs p q r
- type ReplaceAllString p q r = ReplaceAllString' '[] p q r
- type ReplaceAllString' (rs :: [ROpt]) p q r = ReplaceAll' rs p (MakeRR q) r
- type ReplaceOneString p q r = ReplaceOneString' '[] p q r
- type ReplaceOneString' (rs :: [ROpt]) p q r = ReplaceOne' rs p (MakeRR q) r
- data MakeRR p
- data MakeRR1 p
- data MakeRR2 p
- data MakeRR3 p
- data Fst p
- data Snd p
- data Thd p
- type L1 p = Fst p
- type L2 p = Snd p
- type L3 p = Thd p
- data L4 p
- data L5 p
- data L6 p
- type Dup = '(Id, Id)
- data Swap
- data Assoc
- data Unassoc
- data Pairs
- type IsLower = IsCharSet CLower
- type IsUpper = IsCharSet CUpper
- type IsNumber = IsCharSet CNumber
- type IsSpace = IsCharSet CSpace
- type IsPunctuation = IsCharSet CPunctuation
- type IsControl = IsCharSet CControl
- type IsHexDigit = IsCharSet CHexDigit
- type IsOctDigit = IsCharSet COctDigit
- type IsSeparator = IsCharSet CSeparator
- type IsLatin1 = IsCharSet CLatin1
- data FormatTimeP p q
- type ParseTimeP (t :: Type) p q = ParseTimeP' (Hole t) p q
- data ParseTimeP' t p q
- type ParseTimes (t :: Type) p q = ParseTimes' (Hole t) p q
- data ParseTimes' t p q
- type MkDay = MkDay' (Fst Id) (Snd Id) (Thd Id)
- data MkDay' p q r
- data UnMkDay p
- type (+) p q = Add p q
- type (-) p q = Sub p q
- type * p q = Mult p q
- data p / q
- data Negate p
- data Abs p
- data Signum p
- type FromInteger (t :: Type) p = FromInteger' (Hole t) p
- data FromInteger' t n
- type FromIntegral (t :: Type) p = FromIntegral' (Hole t) p
- data FromIntegral' t n
- type Truncate (t :: Type) p = Truncate' (Hole t) p
- data Truncate' t p
- type Ceiling (t :: Type) p = Ceiling' (Hole t) p
- data Ceiling' t p
- type Floor (t :: Type) p = Floor' (Hole t) p
- data Floor' t p
- type Even = Mod I 2 == 0
- type Odd = Mod I 2 == 1
- data Div p q
- data Mod p q
- data DivMod p q
- data QuotRem p q
- type Quot p q = Fst (QuotRem p q)
- type Rem p q = Snd (QuotRem p q)
- data p % q
- type (%-) p q = Negate (p % q)
- type (-%) p q = Negate (p % q)
- data ToRational p
- type FromRational (t :: Type) p = FromRational' (Hole t) p
- data FromRational' t r
- data MkProxy
- type ProxyT (t :: Type) = ProxyT' (Hole t)
- data ProxyT' t
- data Unproxy
- data ShowP p
- type ReadP (t :: Type) p = ReadP' (Hole t) p
- data ReadP' t p
- type ReadQ (t :: Type) p = ReadQ' (Hole t) p
- type ReadQ' t p = ReadMaybe' t p >> MaybeIn (Failp "read failed") (Guard "oops" (Snd Id >> Null) >> Fst Id)
- type ReadMaybe (t :: Type) p = ReadMaybe' (Hole t) p
- data ReadMaybe' t p
- type ReadBase (t :: Type) (n :: Nat) p = ReadBase' (Hole t) n p
- data ReadBase' t (n :: Nat) p
- type ReadBaseInt (n :: Nat) p = ReadBase' (Hole Int) n p
- data ShowBase (n :: Nat) p
- type (&&&) p q = W '(p, q)
- data p *** q
- type First p = p *** I
- type Second q = I *** q
- data p ||| q
- data p +++ q
- type (>) p q = Cmp Cgt p q
- type (>=) p q = Cmp Cge p q
- type (==) p q = Cmp Ceq p q
- type (/=) p q = Cmp Cne p q
- type (<=) p q = Cmp Cle p q
- type (<) p q = Cmp Clt p q
- type (>~) p q = CmpI Cgt p q
- type (>=~) p q = CmpI Cge p q
- type (==~) p q = CmpI Ceq p q
- type (/=~) p q = CmpI Cne p q
- type (<=~) p q = CmpI Cle p q
- type (<~) p q = CmpI Clt p q
- type Gt n = Cmp Cgt I n
- type Ge n = Cmp Cge I n
- type Same n = Cmp Ceq I n
- type Le n = Cmp Cle I n
- type Lt n = Cmp Clt I n
- type Ne n = Cmp Cne I n
- data OrdP p q
- type (==!) p q = OrdP p q
- type OrdA' p q = OrdP (Fst Id >> p) (Snd Id >> q)
- type OrdA p = OrdA' p p
- data OrdI p q
- type (===~) p q = OrdI p q
- data Cmp (o :: OrderingP) p q
- data CmpI (o :: OrderingP) p q
- data Succ p
- data Pred p
- data FromEnum p
- type ToEnum (t :: Type) p = ToEnum' (Hole t) p
- data ToEnum' t p
- data EnumFromTo p q
- data SuccB p q
- type SuccB' q = SuccB (Failp "Succ bounded failed") q
- data PredB p q
- type PredB' q = PredB (Failp "Pred bounded failed") q
- type ToEnumBDef (t :: Type) def = ToEnumBDef' (Hole t) def
- data ToEnumBDef' t def
- type ToEnumBFail (t :: Type) = ToEnumBDef' (Hole t) (Failp "ToEnum bounded failed")
- data Unwrap p
- type Wrap (t :: Type) p = Wrap' (Hole t) p
- data Wrap' t p
- data Coerce (t :: k)
- data Coerce2 (t :: k)
- data Map p q
- data Concat p
- type ConcatMap p q = Concat (Map p q)
- data Partition p q
- type Filter p q = Partition p q >> Fst Id
- data Break p q
- type Span p q = Break (Not p) q
- data Intercalate p q
- data Elem p q
- data Inits
- data Tails
- data Ones p
- type OneP = Guard (PrintF "expected list of length 1 but found length=%d" Len) (Len == 1) >> Head Id
- data Len
- data Length p
- type PadL n p q = Pad True n p q
- type PadR n p q = Pad False n p q
- data Cycle n p
- data SplitAts ns p
- data SplitAt n p
- type Take n p = Fst (SplitAt n p)
- type Drop n p = Snd (SplitAt n p)
- data Min
- data Max
- data Sum
- data IsEmpty
- data Null
- data ToList
- data ToList' p
- type IToList (t :: Type) = IToList' (Hole t) Id
- data IToList' t p
- data FromList (t :: Type)
- type EmptyList (t :: Type) = EmptyList' (Hole t)
- data EmptyList' t
- type Singleton p = p :+ EmptyT [] p
- data Reverse
- data ReverseL
- data SortBy p q
- type SortOn p q = SortBy (OrdA p) q
- type SortOnDesc p q = SortBy (Swap >> OrdA p) q
- type Remove p q = KeepImpl False p q
- type Keep p q = KeepImpl True p q
- data ToListExt
- data FromListExt (t :: Type)
- type MkNothing (t :: Type) = MkNothing' (Hole t)
- data MkNothing' t
- data MkJust p
- type IsNothing = MaybeIn True False
- type IsJust = MaybeIn False True
- type MapMaybe p q = ConcatMap (p >> MaybeIn MEmptyP '[Id]) q
- type CatMaybes q = MapMaybe Id q
- data Just p
- data JustDef p q
- data JustFail p q
- data MaybeIn p q
- data MaybeBool b p
- data PartitionEithers
- type IsLeft = True ||| False
- type IsRight = False ||| True
- type MkLeft (t :: Type) p = MkLeft' (Hole t) p
- data MkLeft' t p
- type MkRight (t :: Type) p = MkRight' (Hole t) p
- data MkRight' t p
- type Left' p = LeftFail "expected Left" p
- type Right' p = RightFail "expected Right" p
- data LeftDef p q
- data LeftFail p q
- data RightDef p q
- data RightFail p q
- data EitherBool b p q
- type MkRightAlt t p = Pure (Either t) p
- type MkLeftAlt t p = MkRightAlt t p >> Swap
- type EitherIn p q = p ||| q
- data p <> q
- data MConcat p
- data STimes n p
- type Sapa = Fst Id <> Snd Id
- type Sapa' (t :: Type) = Wrap t (Fst Id) <> Wrap t (Snd Id)
- type MEmptyT (t :: Type) = MEmptyT' (Hole t)
- data MEmptyT' t
- type MEmptyP = MEmptyT' Unproxy
- type MEmptyT2 t = MEmptyT2' (Hole t)
- data MEmptyT2' t
- data Ix (n :: Nat) def
- type Ix' (n :: Nat) = Ix n (Failp "Ix index not found")
- data IxL p q def
- type (!!) p q = IxL p q (Failp "(!!) index not found")
- data Lookup p q
- type LookupDef x y p = LookupDef' x y p I
- type LookupDef' x y p q = JustDef p (q >> Lookup x y)
- type LookupFail msg x y = LookupFail' msg x y I
- type LookupFail' msg x y q = JustFail msg (q >> Lookup x y)
- data p :+ q
- data p +: q
- data Uncons
- data Unsnoc
- data Head p
- data Tail p
- data Init p
- data Last p
- type HeadDef p q = JustDef p (q >> (Uncons >> FMapFst))
- type HeadFail msg q = JustFail msg (q >> (Uncons >> FMapFst))
- type TailDef p q = JustDef p (q >> (Uncons >> FMapSnd))
- type TailFail msg q = JustFail msg (q >> (Uncons >> FMapSnd))
- type LastDef p q = JustDef p (q >> (Unsnoc >> FMapSnd))
- type LastFail msg q = JustFail msg (q >> (Unsnoc >> FMapSnd))
- type InitDef p q = JustDef p (q >> (Unsnoc >> FMapFst))
- type InitFail msg q = JustFail msg (q >> (Unsnoc >> FMapFst))
- data PartitionThese
- type Thiss = Fst PartitionThese
- type Thats = Snd PartitionThese
- type Theses = Thd PartitionThese
- type This' p = ThisFail "expected This" p
- type That' p = ThatFail "expected That" p
- type These' p = TheseFail "expected These" p
- type IsThis p = IsTh (This ()) p
- type IsThat p = IsTh (That ()) p
- type IsThese p = IsTh (These () ()) p
- type MkThis (t :: Type) p = MkThis' (Hole t) p
- data MkThis' t p
- type MkThat (t :: Type) p = MkThat' (Hole t) 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
- type TheseId p q = TheseIn '(I, p) '(q, I) I
- data TheseX p q r s
- data Scanl p q r
- type ScanN n p q = Scanl (Fst Id >> q) p (EnumFromTo 1 n)
- type ScanNA q = ScanN (Fst Id) (Snd Id) q
- type FoldN n p q = Last (ScanN n p q)
- type Foldl p q r = Last (Scanl p q r)
- data Unfoldr p q
- type IterateN n f = Unfoldr (MaybeBool (Fst Id > 0) '(Snd Id, Pred Id *** f)) '(n, Id)
- type IterateUntil p f = IterateWhile (Not p) f
- type IterateWhile p f = Unfoldr (MaybeBool p '(Id, f)) Id
- type IterateNWhile n p f = '(n, Id) >> (IterateWhile ((Fst Id > 0) && (Snd Id >> p)) (Pred Id *** f) >> Map (Snd Id) Id)
- type IterateNUntil n p f = IterateNWhile n (Not p) f
- data Fail t prt
- type Failp s = Fail Unproxy s
- type Failt (t :: Type) prt = Fail (Hole t) prt
- type FailS s = Fail I s
- data Catch p q
- type Catch' p s = Catch p (FailCatch s)
- data ZipThese p q
- data ZipL l p q
- data ZipR r p q
- data Zip p q
- type Unzip = '(Map (Fst Id) Id, Map (Snd Id) Id)
- type Unzip3 = '(Map (Fst Id) Id, Map (Snd Id) Id, Map (Thd Id) Id)
- data If p q r
- data Case (e :: k0) (ps :: [k]) (qs :: [k1]) (r :: k2)
- type Case' (ps :: [k]) (qs :: [k1]) (r :: k2) = Case (Snd Id >> Failp "Case:no match") ps qs r
- type Case'' s (ps :: [k]) (qs :: [k1]) (r :: k2) = Case (FailCase s) ps qs r
- data Guards (ps :: [(k, k1)])
- type GuardsQuick (prt :: k) (os :: [k1]) = Guards (ToGuardsT prt os)
- data Guard prt p
- type ExitWhen prt p = Guard prt (Not p)
- data GuardSimple p
- data GuardsN prt (n :: Nat) p
- type GuardsDetail (prt :: Symbol) (os :: [(k0, k1)]) = GuardsImplXX (ToGuardsDetailT prt os)
- data Bools (ps :: [(k, k1)])
- type BoolsQuick (prt :: k) (ps :: [k1]) = Bools (ToGuardsT prt ps)
- data BoolsN prt (n :: Nat) p
- data ReadFile p
- type FileExists p = ReadFile p >> IsJust
- data ReadDir p
- type DirExists p = ReadDir p >> IsJust
- data ReadEnv p
- data ReadEnvAll
- data TimeUtc
- data TimeZt
- type AppendFile (s :: Symbol) p = WriteFileImpl (FOther s WFAppend) p
- type WriteFile (s :: Symbol) p = WriteFileImpl (FOther s WFWrite) p
- type WriteFile' (s :: Symbol) p = WriteFileImpl (FOther s WFWriteForce) p
- type Stdout p = WriteFileImpl FStdout p
- type Stderr p = WriteFileImpl FStderr p
- data Stdin
- data ToLower
- data ToUpper
- type Trim p = Trim' True True p
- type TrimStart p = Trim' True False p
- type TrimEnd p = Trim' False True p
- data StripLR (right :: Bool) p q
- type StripRight p q = StripLR True p q
- type StripLeft p q = StripLR False p q
- type IsPrefix p q = IsFixImpl LT False p q
- type IsInfix p q = IsFixImpl EQ False p q
- type IsSuffix p q = IsFixImpl GT False p q
- type IsPrefixI p q = IsFixImpl LT True p q
- type IsInfixI p q = IsFixImpl EQ True p q
- type IsSuffixI p q = IsFixImpl GT True p q
- type FromStringP (t :: Type) p = FromStringP' (Hole t) p
- data FromStringP' 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)
- type FoldMap (t :: Type) p = Map (Wrap t Id) p >> Unwrap (MConcat Id)
- data p <$ q
- data p <* q
- type (*>) p q = q <* p
- data FMapFst
- data FMapSnd
- data Sequence
- type Traverse p q = Map p q >> Sequence
- data Join
- data EmptyT (t :: Type -> Type) p
- data p <|> q
- data Extract
- data Duplicate
- data p $ q
- data q & p
- data Do (ps :: [k])
- data p >> q
- type (<<) p q = q >> p
- type (>>>) p q = p >> q
- data DoN (n :: Nat) p
- data Para (ps :: [k])
- data ParaN (n :: Nat) p
- data Repeat (n :: Nat) p
- data Prime p
- data Luhn p
- data Char1 (s :: Symbol)
- data Hide p
- data Hole (t :: Type)
- data Skip p
- type (|>) p q = Skip p >> q
- type (>|) p q = p >> Skip q
- type (>|>) p q = Skip p >> Skip q
boolean expressions
similar to &&
>>>
pz @(Fst Id && Snd Id) (True, True)
True TrueT
>>>
pz @(Id > 15 && Id < 17) 16
True TrueT
>>>
pz @(Id > 15 && Id < 17) 30
False FalseT
>>>
pz @(Fst Id && (Length (Snd Id) >= 4)) (True,[11,12,13,14])
True TrueT
>>>
pz @(Fst Id && (Length (Snd Id) == 4)) (True,[12,11,12,13,14])
False FalseT
similar to ||
>>>
pz @(Fst Id || (Length (Snd Id) >= 4)) (False,[11,12,13,14])
True TrueT
>>>
pz @(Not (Fst Id) || (Length (Snd Id) == 4)) (True,[12,11,12,13,14])
False FalseT
implication
>>>
pz @(Fst Id ~> (Length (Snd Id) >= 4)) (True,[11,12,13,14])
True TrueT
>>>
pz @(Fst Id ~> (Length (Snd Id) == 4)) (True,[12,11,12,13,14])
False FalseT
>>>
pz @(Fst Id ~> (Length (Snd Id) == 4)) (False,[12,11,12,13,14])
True TrueT
>>>
pz @(Fst Id ~> (Length (Snd Id) >= 4)) (False,[11,12,13,14])
True TrueT
not
function
>>>
pz @(Not Id) False
True TrueT
>>>
pz @(Not Id) True
False FalseT
>>>
pz @(Not (Fst Id)) (True,22)
False FalseT
>>>
pl @(Not (Lt 3)) 13
True (Not (13 < 3)) TrueT
>>>
pz @(Ands Id) [True,True,True]
True TrueT
>>>
pl @(Ands Id) [True,True,True,False]
False (Ands(4) i=3 | [True,True,True,False]) FalseT
>>>
pz @(Ands Id) []
True TrueT
>>>
pz @(Ors Id) [False,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
type Asc = All (Fst Id <= Snd Id) Pairs Source #
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]
True TrueT
>>>
pz @Asc' [1,2,3,4,5,5,7]
False FalseT
>>>
pz @Asc "axacdef"
False FalseT
a type level predicate for a monotonic increasing list
type Asc' = All (Fst Id < Snd Id) Pairs Source #
a type level predicate for a strictly increasing list
type Desc = All (Fst Id >= Snd Id) Pairs Source #
a type level predicate for a monotonic decreasing list
type Desc' = All (Fst Id > Snd Id) Pairs Source #
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]
True TrueT
>>>
pz @(Between 5 8) 6
True TrueT
>>>
pz @(Between 5 8) 9
False FalseT
>>>
pz @(10 % 4 <..> 40 % 5) 4
True TrueT
>>>
pz @(10 % 4 <..> 40 % 5) 33
False FalseT
similar to all
>>>
pl @(All Even Id) [1,5,11,5,3]
False (All i=0 (1 == 0) 5 false) FalseT
>>>
pz @(All Odd Id) [1,5,11,5,3]
True TrueT
>>>
pz @(All Odd Id) []
True TrueT
>>>
pe @(All Even Id) [1,5,11,5,3]
False All i=0 (1 == 0) 5 false | +- 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
>>>
pz @(Any Even Id) [1,5,11,5,3]
False FalseT
>>>
pz @(Any Even Id) [1,5,112,5,3]
True TrueT
>>>
pz @(Any Even Id) []
False FalseT
type AllPositive = All Positive Id Source #
a type level predicate for all positive elements in a list
>>>
pz @AllPositive [1,5,10,2,3]
True TrueT
>>>
pz @AllPositive [0,1,5,10,2,3]
False FalseT
>>>
pz @AllPositive [3,1,-5,10,2,3]
False FalseT
>>>
pz @AllNegative [-1,-5,-10,-2,-3]
True TrueT
type AllNegative = All Negative Id Source #
a type level predicate for all negative elements in a list
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"
True 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"
Present [("13:05:25",["13","05","25"])] PresentT [("13:05:25",["13","05","25"])]
>>>
pz @(Rescan (Snd Id) "13:05:25") ('a',"^(\\d{2}):(\\d{2}):(\\d{2})$")
Present [("13:05:25",["13","05","25"])] PresentT [("13:05:25",["13","05","25"])]
type RescanRanges p q = RescanRanges' '[] p q Source #
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"
Present [((0,8),[(0,2),(3,5),(6,8)])] 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"
Present ["141","201","1","22"] PresentT ["141","201","1","22"]
>>>
pz @(Resplit (Singleton (Fst Id)) (Snd Id)) (':', "12:13:1")
Present ["12","13","1"] PresentT ["12","13","1"]
type ReplaceAll p q r = ReplaceAll' '[] p q r Source #
type ReplaceAll' (rs :: [ROpt]) p q r = ReplaceImpl True rs p q r Source #
type ReplaceOne p q r = ReplaceOne' '[] p q r Source #
type ReplaceOne' (rs :: [ROpt]) p q r = ReplaceImpl False rs p q r Source #
type ReplaceAllString p q r = ReplaceAllString' '[] p q r Source #
type ReplaceAllString' (rs :: [ROpt]) p q r = ReplaceAll' rs p (MakeRR q) r Source #
type ReplaceOneString p q r = ReplaceOneString' '[] p q r Source #
type ReplaceOneString' (rs :: [ROpt]) p q r = ReplaceOne' rs p (MakeRR q) r Source #
Simple replacement string: see ReplaceAllString
and ReplaceOneString
A replacement function (String -> [String] -> String)
which returns the whole match and the groups
Used by sub
and gsub
Requires Text.Show.Functions
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 "\\." (MakeRR2 (Fst Id)) (Snd Id)) (\x -> x <> ":" <> x, "141.201.1.22")
Present "141.:.201.:.1.:.22" PresentT "141.:.201.:.1.:.22"
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+)$" (MakeRR3 (Fst Id)) (Snd Id)) (\ys -> intercalate " | " $ map (show . succ . read @Int) ys, "141.201.1.22")
Present "142 | 202 | 2 | 23" PresentT "142 | 202 | 2 | 23"
tuple expressions
similar to fst
>>>
pz @(Fst Id) (10,"Abc")
Present 10 PresentT 10
>>>
pz @(Fst Id) (10,"Abc",'x')
Present 10 PresentT 10
>>>
pz @(Fst Id) (10,"Abc",'x',False)
Present 10 PresentT 10
similar to snd
>>>
pz @(Snd Id) (10,"Abc")
Present "Abc" PresentT "Abc"
>>>
pz @(Snd Id) (10,"Abc",True)
Present "Abc" PresentT "Abc"
similar to 3rd element in a n-tuple
>>>
pz @(Thd Id) (10,"Abc",133)
Present 133 PresentT 133
>>>
pz @(Thd Id) (10,"Abc",133,True)
Present 133 PresentT 133
similar to 4th element in a n-tuple
>>>
pz @(L4 Id) (10,"Abc",'x',True)
Present True PresentT True
>>>
pz @(L4 (Fst (Snd Id))) ('x',((10,"Abc",'x',999),"aa",1),9)
Present 999 PresentT 999
similar to 5th element in a n-tuple
>>>
pz @(L5 Id) (10,"Abc",'x',True,1)
Present 1 PresentT 1
similar to 6th element in a n-tuple
>>>
pz @(L6 Id) (10,"Abc",'x',True,1,99)
Present 99 PresentT 99
swaps using swap
>>>
pz @Swap (Left 123)
Present Right 123 PresentT (Right 123)
>>>
pz @Swap (Right 123)
Present Left 123 PresentT (Left 123)
>>>
pz @Swap (These 'x' 123)
Present These 123 'x' PresentT (These 123 'x')
>>>
pz @Swap (This 'x')
Present That 'x' PresentT (That 'x')
>>>
pz @Swap (That 123)
Present This 123 PresentT (This 123)
>>>
pz @Swap (123,'x')
Present ('x',123) PresentT ('x',123)
>>>
pz @Swap (Left "abc")
Present Right "abc" PresentT (Right "abc")
>>>
pz @Swap (Right 123)
Present Left 123 PresentT (Left 123)
assoc using assoc
>>>
pz @Assoc (This (These 123 'x'))
Present These 123 (This 'x') PresentT (These 123 (This 'x'))
>>>
pz @Assoc ((99,'a'),True)
Present (99,('a',True)) PresentT (99,('a',True))
>>>
pz @Assoc ((99,'a'),True)
Present (99,('a',True)) PresentT (99,('a',True))
>>>
pz @Assoc (Right "Abc" :: Either (Either () ()) String)
Present Right (Right "Abc") PresentT (Right (Right "Abc"))
>>>
pz @Assoc (Left (Left 'x'))
Present Left 'x' PresentT (Left 'x')
unassoc using unassoc
>>>
pz @Unassoc (These 123 (This 'x'))
Present This (These 123 'x') PresentT (This (These 123 'x'))
>>>
pz @Unassoc (99,('a',True))
Present ((99,'a'),True) PresentT ((99,'a'),True)
>>>
pz @Unassoc (This 10 :: These Int (These Bool ()))
Present This (This 10) PresentT (This (This 10))
>>>
pz @Unassoc (Right (Right 123))
Present Right 123 PresentT (Right 123)
>>>
pz @Unassoc (Left 'x' :: Either Char (Either Bool Double))
Present Left (Left 'x') PresentT (Left (Left 'x'))
creates a list of overlapping pairs of elements. requires two or more elements
>>>
pz @Pairs [1,2,3,4]
Present [(1,2),(2,3),(3,4)] PresentT [(1,2),(2,3),(3,4)]
>>>
pz @Pairs []
Error Pairs no data found FailT "Pairs no data found"
>>>
pz @Pairs [1]
Error Pairs only one element found FailT "Pairs only one element found"
character expressions
type IsLower = IsCharSet CLower Source #
predicate for determining if a string is all lowercase
>>>
pz @IsLower "abcdef213"
False FalseT
>>>
pz @IsLower "abcdef"
True TrueT
>>>
pz @IsLower ""
True TrueT
>>>
pz @IsLower "abcdefG"
False FalseT
type IsNumber = IsCharSet CNumber Source #
predicate for determining if the string is all digits
>>>
pz @IsNumber "213G"
False FalseT
>>>
pz @IsNumber "929"
True TrueT
type IsPunctuation = IsCharSet CPunctuation Source #
type IsHexDigit = IsCharSet CHexDigit Source #
type IsOctDigit = IsCharSet COctDigit Source #
type IsSeparator = IsCharSet CSeparator Source #
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) (read "2019-05-24 05:19:59" :: LocalTime)
Present "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", read "2019-05-24" :: Day)
Present "the date is 24/05/2019" 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 |
type ParseTimeP (t :: Type) p q = ParseTimeP' (Hole t) p q Source #
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"
Present 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")
Present 2019-05-24 05:19:59 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 |
type ParseTimes (t :: Type) p q = ParseTimes' (Hole t) p q Source #
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") ()
Present 2019-03-11 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")
Present 2019-03-11 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 (2019,12,30)
Present Just (2019-12-30,1,1) PresentT (Just (2019-12-30,1,1))
>>>
pz @(MkDay' (Fst Id) (Snd Id) (Thd Id)) (2019,99,99999)
Present Nothing PresentT Nothing
>>>
pz @MkDay (1999,3,13)
Present Just (1999-03-13,10,6) PresentT (Just (1999-03-13,10,6))
uncreate a Day
returning year month and day
>>>
pz @(UnMkDay Id) (read "2019-12-30")
Present (2019,12,30) PresentT (2019,12,30)
numeric expressions
fractional division
>>>
pz @(Fst Id / Snd Id) (13,2)
Present 6.5 PresentT 6.5
>>>
pz @(ToRational 13 / Id) 0
Error (/) zero denominator FailT "(/) zero denominator"
>>>
pz @(12 % 7 / 14 % 5 + Id) 12.4
Present 3188 % 245 PresentT (3188 % 245)
similar to negate
>>>
pz @(Negate Id) 14
Present -14 PresentT (-14)
>>>
pz @(Negate (Fst Id * Snd Id)) (14,3)
Present -42 PresentT (-42)
>>>
pz @(Negate (15 %- 4)) "abc"
Present 15 % 4 PresentT (15 % 4)
>>>
pz @(Negate (15 % 3)) ()
Present (-5) % 1 PresentT ((-5) % 1)
>>>
pz @(Negate (Fst Id % Snd Id)) (14,3)
Present (-14) % 3 PresentT ((-14) % 3)
similar to abs
>>>
pz @(Abs Id) (-14)
Present 14 PresentT 14
>>>
pz @(Abs (Snd Id)) ("xx",14)
Present 14 PresentT 14
>>>
pz @(Abs Id) 0
Present 0 PresentT 0
>>>
pz @(Abs (Negate 44)) "aaa"
Present 44 PresentT 44
similar to signum
>>>
pz @(Signum Id) (-14)
Present -1 PresentT (-1)
>>>
pz @(Signum Id) 14
Present 1 PresentT 1
>>>
pz @(Signum Id) 0
Present 0 PresentT 0
type FromInteger (t :: Type) p = FromInteger' (Hole t) p Source #
data FromInteger' t n Source #
fromInteger
function where you need to provide the type 't' of the result
>>>
pz @(FromInteger (SG.Sum _) Id) 23
Present Sum {getSum = 23} PresentT (Sum {getSum = 23})
>>>
pz @(FromInteger Rational 44) 12
Present 44 % 1 PresentT (44 % 1)
>>>
pz @(FromInteger Rational Id) 12
Present 12 % 1 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 |
type FromIntegral (t :: Type) p = FromIntegral' (Hole t) p Source #
data FromIntegral' t n Source #
fromIntegral
function where you need to provide the type 't' of the result
>>>
pz @(FromIntegral (SG.Sum _) Id) 23
Present Sum {getSum = 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)
Present 4 PresentT 4
ceiling
function where you need to provide the type 't' of the result
>>>
pz @(Ceiling Int Id) (23 % 5)
Present 5 PresentT 5
floor
function where you need to provide the type 't' of the result
>>>
pz @(Floor Int Id) (23 % 5)
Present 4 PresentT 4
type Even = Mod I 2 == 0 Source #
similar to even
>>>
pz @(Map Even Id) [9,-4,12,1,2,3]
Present [False,True,True,False,True,False] PresentT [False,True,True,False,True,False]
>>>
pz @(Map '(Even,Odd) Id) [9,-4,12,1,2,3]
Present [(False,True),(True,False),(True,False),(False,True),(True,False),(False,True)] PresentT [(False,True),(True,False),(True,False),(False,True),(True,False),(False,True)]
similar to div
>>>
pz @(Div (Fst Id) (Snd Id)) (10,4)
Present 2 PresentT 2
>>>
pz @(Div (Fst Id) (Snd Id)) (10,0)
Error Div zero denominator FailT "Div zero denominator"
similar to mod
>>>
pz @(Mod (Fst Id) (Snd Id)) (10,3)
Present 1 PresentT 1
>>>
pz @(Mod (Fst Id) (Snd Id)) (10,0)
Error Mod zero denominator FailT "Mod zero denominator"
similar to divMod
>>>
pz @(DivMod (Fst Id) (Snd Id)) (10,3)
Present (3,1) PresentT (3,1)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (10,-3)
Present (-4,-2) PresentT (-4,-2)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (-10,3)
Present (-4,2) PresentT (-4,2)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (-10,-3)
Present (3,-1) PresentT (3,-1)
>>>
pz @(DivMod (Fst Id) (Snd Id)) (10,0)
Error DivMod zero denominator FailT "DivMod zero denominator"
similar to quotRem
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (10,3)
Present (3,1) PresentT (3,1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (10,-3)
Present (-3,1) PresentT (-3,1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (-10,-3)
Present (3,-1) PresentT (3,-1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (-10,3)
Present (-3,-1) PresentT (-3,-1)
>>>
pz @(QuotRem (Fst Id) (Snd Id)) (10,0)
Error QuotRem zero denominator FailT "QuotRem zero denominator"
rational numbers
creates a Rational
value
>>>
pz @(Id < 21 % 5) (-3.1)
True TrueT
>>>
pz @(Id < 21 % 5) 4.5
False FalseT
>>>
pz @(Fst Id % Snd Id) (13,2)
Present 13 % 2 PresentT (13 % 2)
>>>
pz @(13 % Id) 0
Error MkRatio zero denominator FailT "MkRatio zero denominator"
>>>
pz @(4 % 3 + 5 % 7) "asfd"
Present 43 % 21 PresentT (43 % 21)
>>>
pz @(4 %- 7 * 5 %- 3) "asfd"
Present 20 % 21 PresentT (20 % 21)
>>>
pz @(Negate (14 % 3)) ()
Present (-14) % 3 PresentT ((-14) % 3)
>>>
pz @(14 % 3) ()
Present 14 % 3 PresentT (14 % 3)
>>>
pz @(Negate (14 % 3) ==! FromIntegral _ (Negate 5)) ()
Present GT PresentT GT
>>>
pz @(14 -% 3 ==! 5 %- 1) "aa"
Present GT PresentT GT
>>>
pz @(Negate (14 % 3) ==! Negate 5 % 2) ()
Present LT PresentT LT
>>>
pz @(14 -% 3 * 5 -% 1) ()
Present 70 % 3 PresentT (70 % 3)
>>>
pz @(14 % 3 ==! 5 % 1) ()
Present LT PresentT LT
>>>
pz @(15 % 3 / 4 % 2) ()
Present 5 % 2 PresentT (5 % 2)
data ToRational p Source #
toRational
function
>>>
pz @(ToRational Id) 23.5
Present 47 % 2 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 |
type FromRational (t :: Type) p = FromRational' (Hole t) p Source #
data FromRational' t r Source #
fromRational
function where you need to provide the type 't' of the result
>>>
pz @(FromRational Rational Id) 23.5
Present 47 % 2 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'
Present Proxy PresentT Proxy
read / show expressions
similar to show
>>>
pz @(ShowP Id) [4,8,3,9]
Present "[4,8,3,9]" PresentT "[4,8,3,9]"
>>>
pz @(ShowP Id) 'x'
Present "'x'" PresentT "'x'"
>>>
pz @(ShowP (42 %- 10)) 'x'
Present "(-21) % 5" 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"
Present 4 % 5 PresentT (4 % 5)
>>>
pz @(ReadP Day Id >> Between (ReadP Day "2017-04-11") (ReadP Day "2018-12-30")) "2018-10-12"
True TrueT
>>>
pz @(ReadP Day Id >> Between (ReadP Day "2017-04-11") (ReadP Day "2018-12-30")) "2016-10-12"
False FalseT
type ReadQ' t p = ReadMaybe' t p >> MaybeIn (Failp "read failed") (Guard "oops" (Snd Id >> Null) >> Fst Id) Source #
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"
Present Just (123,"x") PresentT (Just (123,"x"))
>>>
pz @(ReadMaybe Int Id) "123"
Present Just (123,"") PresentT (Just (123,""))
>>>
pz @(ReadMaybe Int Id) "x123"
Present Nothing 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"
Present 4077 PresentT 4077
>>>
pz @(ReadBase Int 16 Id) "-ff"
Present -255 PresentT (-255)
>>>
pz @(ReadBase Int 2 Id) "10010011"
Present 147 PresentT 147
>>>
pz @(ReadBase Int 8 Id) "Abff"
Error invalid base 8 FailT "invalid base 8"
supports negative numbers unlike readInt
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
Present "fed" PresentT "fed"
>>>
pz @(ShowBase 16 Id) (-255)
Present "-ff" PresentT "-ff"
>>>
pz @(ShowBase 2 Id) 147
Present "10010011" PresentT "10010011"
>>>
pz @(ShowBase 2 (Negate 147)) "whatever"
Present "-10010011" PresentT "-10010011"
arrow expressions
data p *** q infixr 3 Source #
similar to ***
>>>
pz @(Pred Id *** ShowP Id) (13, True)
Present (12,"True") PresentT (12,"True")
data p ||| q infixr 2 Source #
similar |||
>>>
pz @(Pred Id ||| Id) (Left 13)
Present 12 PresentT 12
>>>
pz @(ShowP Id ||| Id) (Right "hello")
Present "hello" PresentT "hello"
data p +++ q infixr 2 Source #
similar +++
>>>
pz @(Pred Id +++ Id) (Left 13)
Present Left 12 PresentT (Left 12)
>>>
pz @(ShowP Id +++ Reverse) (Right "hello")
Present Right "olleh" PresentT (Right "olleh")
compare expressions
type OrdA' p q = OrdP (Fst Id >> p) (Snd Id >> q) Source #
similar to compare
>>>
pz @(Fst Id ==! Snd Id) (10,9)
Present GT PresentT GT
>>>
pz @(14 % 3 ==! Fst Id %- Snd Id) (-10,7)
Present GT PresentT GT
>>>
pz @(Fst Id ==! Snd Id) (10,11)
Present LT PresentT LT
>>>
pz @(Snd Id ==! (Fst Id >> Snd Id >> Head Id)) (('x',[10,12,13]),10)
Present EQ PresentT EQ
>>>
pz @(Snd Id ==! Head (Snd (Fst Id))) (('x',[10,12,13]),10)
Present EQ PresentT EQ
compare two strings ignoring case
>>>
pz @(Fst Id ===~ Snd Id) ("abC","aBc")
Present EQ PresentT EQ
>>>
pz @(Fst Id ===~ Snd Id) ("abC","DaBc")
Present LT PresentT LT
data Cmp (o :: OrderingP) p q Source #
compare two values using the given ordering 'o'
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
Present 14 PresentT 14
>>>
pz @(Succ Id) LT
Present EQ PresentT EQ
>>>
pz @(Succ Id) GT
Error Succ IO e=Prelude.Enum.Ordering.succ: bad argument FailT "Succ IO e=Prelude.Enum.Ordering.succ: bad argument"
unbounded pred
function
>>>
pz @(Pred Id) 13
Present 12 PresentT 12
>>>
pz @(Pred Id) LT
Error Pred IO e=Prelude.Enum.Ordering.pred: bad argument FailT "Pred IO e=Prelude.Enum.Ordering.pred: bad argument"
fromEnum
function
>>>
pz @(FromEnum Id) 'x'
Present 120 PresentT 120
unsafe toEnum
function
>>>
pz @(ToEnum Char Id) 120
Present 'x' PresentT 'x'
data EnumFromTo p q Source #
similar to enumFromTo
>>>
pz @(EnumFromTo 2 5) ()
Present [2,3,4,5] PresentT [2,3,4,5]
>>>
pz @(EnumFromTo 'LT 'GT) ()
Present [LT,EQ,GT] PresentT [LT,EQ,GT]
>>>
pz @(EnumFromTo 'GT 'LT) ()
Present [] PresentT []
>>>
pz @(EnumFromTo (Pred Id) (Succ Id)) (SG.Max 10)
Present [Max {getMax = 9},Max {getMax = 10},Max {getMax = 11}] PresentT [Max {getMax = 9},Max {getMax = 10},Max {getMax = 11}]
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 |
bounded enum expressions
bounded succ
function
>>>
pz @(SuccB' Id) (13 :: Int)
Present 14 PresentT 14
>>>
pz @(SuccB' Id) LT
Present EQ PresentT EQ
>>>
pz @(SuccB 'LT Id) GT
Present LT PresentT LT
>>>
pz @(SuccB' Id) GT
Error Succ bounded failed FailT "Succ bounded failed"
bounded pred
function
>>>
pz @(PredB' Id) (13 :: Int)
Present 12 PresentT 12
>>>
pz @(PredB' Id) LT
Error Pred bounded failed FailT "Pred bounded failed"
type ToEnumBDef (t :: Type) def = ToEnumBDef' (Hole t) def Source #
data ToEnumBDef' t def Source #
bounded toEnum
function
>>>
pz @(ToEnumBDef Ordering LT) 2
Present GT PresentT GT
>>>
pz @(ToEnumBDef Ordering LT) 6
Present LT PresentT LT
>>>
pz @(ToEnumBFail Ordering) 6
Error ToEnum bounded failed FailT "ToEnum bounded failed"
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 |
type ToEnumBFail (t :: Type) = ToEnumBDef' (Hole t) (Failp "ToEnum bounded failed") Source #
wrap / unwrap expressions
unwraps a value (see _Wrapped'
)
>>>
pz @(Unwrap Id) (SG.Sum (-13))
Present -13 PresentT (-13)
wraps a value (see _Wrapped'
and _Unwrapped'
)
>>>
:m + Data.List.NonEmpty
>>>
pz @(Wrap (SG.Sum _) Id) (-13)
Present Sum {getSum = -13} PresentT (Sum {getSum = -13})
>>>
pz @(Wrap SG.Any (Ge 4)) 13
Present Any {getAny = True} PresentT (Any {getAny = True})
>>>
pz @(Wrap (NonEmpty _) (Uncons >> 'Just Id)) "abcd"
Present 'a' :| "bcd" PresentT ('a' :| "bcd")
similar to coerce
>>>
pz @(Coerce (SG.Sum Integer)) (Identity (-13))
Present Sum {getSum = -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]
Present [Sum {getSum = -13},Sum {getSum = 4},Sum {getSum = 99}] PresentT [Sum {getSum = -13},Sum {getSum = 4},Sum {getSum = 99}]
>>>
pz @(Coerce2 (SG.Sum Integer)) (Just (Identity (-13)))
Present Just (Sum {getSum = -13}) PresentT (Just (Sum {getSum = -13}))
>>>
pz @(Coerce2 (SG.Sum Int)) (Nothing @(Identity Int))
Present Nothing PresentT Nothing
list / foldable expressions
similar to map
>>>
pz @(Map (Pred Id) Id) [1..5]
Present [0,1,2,3,4] PresentT [0,1,2,3,4]
similar to concat
>>>
pz @(Concat Id) ["abc","D","eF","","G"]
Present "abcDeFG" PresentT "abcDeFG"
>>>
pz @(Concat (Snd Id)) ('x',["abc","D","eF","","G"])
Present "abcDeFG" PresentT "abcDeFG"
similar to partition
>>>
pz @(Partition (Ge 3) Id) [10,4,1,7,3,1,3,5]
Present ([10,4,7,3,3,5],[1,1]) PresentT ([10,4,7,3,3,5],[1,1])
>>>
pz @(Partition (Prime Id) Id) [10,4,1,7,3,1,3,5]
Present ([7,3,3,5],[10,4,1,1]) PresentT ([7,3,3,5],[10,4,1,1])
>>>
pz @(Partition (Ge 300) Id) [10,4,1,7,3,1,3,5]
Present ([],[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]
Present ([10,4,1,7,3,1,3,5],[]) PresentT ([10,4,1,7,3,1,3,5],[])
similar to break
>>>
pz @(Break (Ge 3) Id) [10,4,1,7,3,1,3,5]
Present ([],[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]
Present ([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"]) ()
Present ["xxxx","aB","yz","aB","z","aB","www","aB","xyz"] PresentT ["xxxx","aB","yz","aB","z","aB","www","aB","xyz"]
>>>
pz @(Intercalate '[W 99,Negate 98] Id) [1..5]
Present [1,99,-98,2,99,-98,3,99,-98,4,99,-98,5] PresentT [1,99,-98,2,99,-98,3,99,-98,4,99,-98,5]
>>>
pz @(Intercalate '[99,100] Id) [1..5]
Present [1,99,100,2,99,100,3,99,100,4,99,100,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")
True TrueT
>>>
pz @(Elem (Fst Id) (Snd Id)) ('z',"abcdxy")
False FalseT
similar to inits
>>>
pz @Inits [4,8,3,9]
Present [[],[4],[4,8],[4,8,3],[4,8,3,9]] PresentT [[],[4],[4,8],[4,8,3],[4,8,3,9]]
>>>
pz @Inits []
Present [[]] PresentT [[]]
similar to tails
>>>
pz @Tails [4,8,3,9]
Present [[4,8,3,9],[8,3,9],[3,9],[9],[]] PresentT [[4,8,3,9],[8,3,9],[3,9],[9],[]]
>>>
pz @Tails []
Present [[]] PresentT [[]]
split a list into single values
>>>
pz @(Ones Id) [4,8,3,9]
Present [[4],[8],[3],[9]] PresentT [[4],[8],[3],[9]]
>>>
pz @(Ones Id) []
Present [] PresentT []
type OneP = Guard (PrintF "expected list of length 1 but found length=%d" Len) (Len == 1) >> Head Id Source #
similar to length
>>>
pz @Len [10,4,5,12,3,4]
Present 6 PresentT 6
>>>
pz @Len []
Present 0 PresentT 0
similar to length
for Foldable
instances
>>>
pz @(Length Id) (Left "aa")
Present 0 PresentT 0
>>>
pz @(Length Id) (Right "aa")
Present 1 PresentT 1
>>>
pz @(Length (Right' Id)) (Right "abcd")
Present 4 PresentT 4
>>>
pz @(Length (Thd (Snd Id))) (True,(23,'x',[10,9,1,3,4,2]))
Present 6 PresentT 6
similar to cycle
but for a fixed number 'n'
>>>
pz @(Cycle 5 Id) [1,2]
Present [1,2,1,2,1] 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"
Present ["he","llo"," ","w","orld"] PresentT ["he","llo"," ","w","orld"]
>>>
pz @(SplitAts '[2] Id) "hello world"
Present ["he","llo world"] PresentT ["he","llo world"]
>>>
pz @(SplitAts '[10,1,1,5] Id) "hello world"
Present ["hello worl","d","",""] PresentT ["hello worl","d","",""]
similar to splitAt
>>>
pz @(SplitAt 4 Id) "hello world"
Present ("hell","o world") PresentT ("hell","o world")
>>>
pz @(SplitAt 20 Id) "hello world"
Present ("hello world","") PresentT ("hello world","")
>>>
pz @(SplitAt 0 Id) "hello world"
Present ("","hello world") PresentT ("","hello world")
>>>
pz @(SplitAt (Snd Id) (Fst Id)) ("hello world",4)
Present ("hell","o world") PresentT ("hell","o world")
similar to minimum
>>>
pz @Min [10,4,5,12,3,4]
Present 3 PresentT 3
>>>
pz @Min []
Error empty list FailT "empty list"
similar to maximum
>>>
pz @Max [10,4,5,12,3,4]
Present 12 PresentT 12
>>>
pz @Max []
Error empty list FailT "empty list"
similar to sum
>>>
pz @Sum [10,4,5,12,3,4]
Present 38 PresentT 38
>>>
pz @Sum []
Present 0 PresentT 0
similar to null
using AsEmpty
>>>
pz @IsEmpty [1,2,3,4]
False FalseT
>>>
pz @IsEmpty []
True TrueT
>>>
pz @IsEmpty LT
False FalseT
>>>
pz @IsEmpty EQ
True TrueT
similar to toList
>>>
pz @ToList ("aBc" :: String)
Present "aBc" PresentT "aBc"
>>>
pz @ToList (Just 14)
Present [14] PresentT [14]
>>>
pz @ToList Nothing
Present [] PresentT []
>>>
pz @ToList (Left "xx")
Present [] PresentT []
>>>
pz @ToList (These 12 "xx")
Present ["xx"] PresentT ["xx"]
similar to toList
>>>
pz @(ToList' Id) ("aBc" :: String)
Present "aBc" PresentT "aBc"
>>>
pz @(ToList' Id) (Just 14)
Present [14] PresentT [14]
>>>
pz @(ToList' Id) Nothing
Present [] PresentT []
>>>
pz @(ToList' Id) (Left "xx")
Present [] PresentT []
>>>
pz @(ToList' Id) (These 12 "xx")
Present ["xx"] PresentT ["xx"]
similar to itoList
>>>
pz @(IToList _) ("aBc" :: String)
Present [(0,'a'),(1,'B'),(2,'c')] PresentT [(0,'a'),(1,'B'),(2,'c')]
data EmptyList' t Source #
creates an empty list of the given type
>>>
pz @(Id :+ EmptyList _) 99
Present [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 |
type Singleton p = p :+ EmptyT [] p Source #
creates a singleton from a value
>>>
pz @(Singleton (Char1 "aBc")) ()
Present "a" PresentT "a"
>>>
pz @(Singleton Id) False
Present [False] PresentT [False]
>>>
pz @(Singleton (Snd Id)) (False,"hello")
Present ["hello"] PresentT ["hello"]
similar to reverse
>>>
pz @Reverse [1,2,4]
Present [4,2,1] PresentT [4,2,1]
>>>
pz @Reverse "AbcDeF"
Present "FeDcbA" PresentT "FeDcbA"
reverses using reversing
>>>
pz @ReverseL (T.pack "AbcDeF")
Present "FeDcbA" PresentT "FeDcbA"
>>>
pz @ReverseL ("AbcDeF" :: String)
Present "FeDcbA" PresentT "FeDcbA"
sort a list
>>>
pz @(SortOn (Fst Id) Id) [(10,"abc"), (3,"def"), (4,"gg"), (10,"xyz"), (1,"z")]
Present [(1,"z"),(3,"def"),(4,"gg"),(10,"abc"),(10,"xyz")] 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")]
Present [(20,"bbb"),(10,"ab"),(4,"x")] PresentT [(20,"bbb"),(10,"ab"),(4,"x")]
>>>
pz @(SortBy 'LT Id) [1,5,2,4,7,0]
Present [1,5,2,4,7,0] PresentT [1,5,2,4,7,0]
>>>
pz @(SortBy 'GT Id) [1,5,2,4,7,0]
Present [0,7,4,2,5,1] 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")]
Present [(4,"a"),(4,"x"),(4,"y"),(10,"ab"),(20,"bbb")] 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")]
Present [(4,"y"),(4,"x"),(4,"a"),(10,"ab"),(20,"bbb")] PresentT [(4,"y"),(4,"x"),(4,"a"),(10,"ab"),(20,"bbb")]
overloaded list expressions
invokes toList
>>>
pz @ToListExt (M.fromList [(1,'x'),(4,'y')])
Present [(1,'x'),(4,'y')] PresentT [(1,'x'),(4,'y')]
>>>
pz @ToListExt (T.pack "abc")
Present "abc" PresentT "abc"
data FromListExt (t :: Type) Source #
invokes fromList
requires the OverloadedLists extension
>>>
:set -XOverloadedLists
>>>
pz @(FromListExt (M.Map _ _)) [(4,"x"),(5,"dd")]
Present fromList [(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
Present Just 44 PresentT (Just 44)
tries to extract a
from Maybe a
otherwise it fails
>>>
pz @(Just Id) (Just "abc")
Present "abc" PresentT "abc"
>>>
pz @(Just Id) Nothing
Error Just(empty) FailT "Just(empty)"
extract the value from a Maybe
otherwise use the default value
>>>
pz @(JustDef (1 % 4) Id) (Just 20.4)
Present 102 % 5 PresentT (102 % 5)
>>>
pz @(JustDef (1 % 4) Id) Nothing
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(JustDef (MEmptyT _) Id) (Just "xy")
Present "xy" PresentT "xy"
>>>
pz @(JustDef (MEmptyT _) Id) Nothing
Present () PresentT ()
>>>
pz @(JustDef (MEmptyT (SG.Sum _)) Id) Nothing
Present Sum {getSum = 0} PresentT (Sum {getSum = 0})
extract the value from a Maybe
or fail
>>>
pz @(JustFail "nope" Id) (Just 99)
Present 99 PresentT 99
>>>
pz @(JustFail "nope" Id) Nothing
Error nope FailT "nope"
>>>
pz @(JustFail (PrintF "oops=%d" (Snd Id)) (Fst Id)) (Nothing, 123)
Error oops=123 FailT "oops=123"
>>>
pz @(JustFail (PrintF "oops=%d" (Snd Id)) (Fst Id)) (Just 'x', 123)
Present 'x' 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)
Present "19" PresentT "19"
>>>
pz @(MaybeIn "found nothing" (ShowP (Pred Id))) Nothing
Present "found 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
Present Just 24 PresentT (Just 24)
>>>
pz @(MaybeBool (Id > 4) Id) (-5)
Present Nothing PresentT Nothing
either expressions
data PartitionEithers Source #
similar to partitionEithers
>>>
pz @PartitionEithers [Left 'a',Right 2,Left 'c',Right 4,Right 99]
Present ("ac",[2,4,99]) PresentT ("ac",[2,4,99])
>>>
pz @PartitionEithers [Right 2,Right 4,Right 99]
Present ([],[2,4,99]) PresentT ([],[2,4,99])
>>>
pz @PartitionEithers [Left 'a',Left 'c']
Present ("ac",[]) PresentT ("ac",[])
>>>
pz @PartitionEithers ([] @(Either _ _))
Present ([],[]) 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
Present Left 44 PresentT (Left 44)
Right
constructor
>>>
pz @(MkRight _ Id) 44
Present Right 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)
Present 102 % 5 PresentT (102 % 5)
>>>
pz @(LeftDef (1 % 4) Id) (Right "aa")
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(LeftDef (PrintT "found right=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Right "xy")
Present "found right=xy fst=123" PresentT "found right=xy fst=123"
>>>
pz @(LeftDef (MEmptyT _) Id) (Right 222)
Present () PresentT ()
>>>
pz @(LeftDef (MEmptyT (SG.Sum _)) Id) (Right 222)
Present Sum {getSum = 0} PresentT (Sum {getSum = 0})
extract the Left value from an Either
otherwise fail with an error 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)
Present 20.4 PresentT 20.4
>>>
pz @(LeftFail "oops" Id) (Right "aa")
Error oops FailT "oops"
>>>
pz @(LeftFail (PrintT "found right=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Right "xy")
Error found right=xy fst=123 FailT "found right=xy fst=123"
>>>
pz @(LeftFail (MEmptyT _) Id) (Right 222)
Error 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)
Present 102 % 5 PresentT (102 % 5)
>>>
pz @(RightDef (1 % 4) Id) (Left "aa")
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(RightDef (PrintT "found left=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Left "xy")
Present "found left=xy fst=123" PresentT "found left=xy fst=123"
>>>
pz @(RightDef (MEmptyT _) Id) (Left 222)
Present () PresentT ()
>>>
pz @(RightDef (MEmptyT (SG.Sum _)) Id) (Left 222)
Present Sum {getSum = 0} PresentT (Sum {getSum = 0})
extract the Right value from an Either
otherwise fail with an error 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)
Present 20.4 PresentT 20.4
>>>
pz @(RightFail "oops" Id) (Left "aa")
Error oops FailT "oops"
>>>
pz @(RightFail (PrintT "found left=%s fst=%d" '(Fst Id,Fst (Snd Id))) (Snd Id)) (123,Left "xy")
Error found left=xy fst=123 FailT "found left=xy fst=123"
>>>
pz @(RightFail (MEmptyT _) Id) (Left 222)
Error 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))
Present Right 999 PresentT (Right 999)
>>>
pz @(EitherBool (Fst Id > 4) (Fst (Snd Id)) (Snd (Snd Id))) (1,(-1,999))
Present Left (-1) 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 |
type MkRightAlt t p = Pure (Either t) p Source #
semigroup / monoid expressions
similar to <>
>>>
pz @(Fst Id <> Snd Id) ("abc","def")
Present "abcdef" PresentT "abcdef"
>>>
pz @("abcd" <> "ef" <> Id) "ghi"
Present "abcdefghi" PresentT "abcdefghi"
>>>
pz @("abcd" <> "ef" <> Id) "ghi"
Present "abcdefghi" PresentT "abcdefghi"
>>>
pz @(Wrap (SG.Sum _) Id <> FromInteger _ 10) 13
Present Sum {getSum = 23} PresentT (Sum {getSum = 23})
>>>
pz @(Wrap (SG.Product _) Id <> FromInteger _ 10) 13
Present Product {getProduct = 130} PresentT (Product {getProduct = 130})
>>>
pz @('(FromInteger _ 10,"def") <> Id) (SG.Sum 12, "_XYZ")
Present (Sum {getSum = 22},"def_XYZ") PresentT (Sum {getSum = 22},"def_XYZ")
>>>
pz @(Sapa' (SG.Max _)) (10,12)
Present Max {getMax = 12} PresentT (Max {getMax = 12})
>>>
pz @(Sapa' (SG.Sum _)) (10,12)
Present Sum {getSum = 22} PresentT (Sum {getSum = 22})
similar to mconcat
>>>
pz @(MConcat Id) [SG.Sum 44, SG.Sum 12, SG.Sum 3]
Present Sum {getSum = 59} PresentT (Sum {getSum = 59})
similar to stimes
>>>
pz @(STimes 4 Id) (SG.Sum 3)
Present Sum {getSum = 12} PresentT (Sum {getSum = 12})
>>>
pz @(STimes 4 Id) "ab"
Present "abababab" PresentT "abababab"
similar to mempty
>>>
pz @(MEmptyT (SG.Sum Int)) ()
Present Sum {getSum = 0} 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 @(MEmptyT2 (SG.Product Int)) [Identity (-13), Identity 4, Identity 99]
Present [Product {getProduct = 1},Product {getProduct = 1},Product {getProduct = 1}] 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"]
Present "G" PresentT "G"
>>>
pz @(Ix 40 "not found") ["abc","D","eF","","G"]
Present "not found" PresentT "not found"
similar to !!
leveraging Ixed
>>>
import qualified Data.Map.Strict as M
>>>
pz @(Id !! 2) ["abc","D","eF","","G"]
Present "eF" PresentT "eF"
>>>
pz @(Id !! 20) ["abc","D","eF","","G"]
Error (!!) index not found FailT "(!!) index not found"
>>>
pz @(Id !! "eF") (M.fromList (flip zip [0..] ["abc","D","eF","","G"]))
Present 2 PresentT 2
Instances
(P q a, P p a, Show (PP p a), Ixed (PP p a), PP q a ~ Index (PP p a), Show (Index (PP p a)), Show (IxValue (PP p a)), P r (Proxy (IxValue (PP p a))), PP r (Proxy (IxValue (PP p a))) ~ IxValue (PP p a)) => P (IxL p q r :: Type) a Source # | |
type PP (IxL p q r :: Type) a Source # | |
Defined in Predicate.Prelude |
lookup
leveraging Ixed
>>>
pz @(Lookup Id 2) ["abc","D","eF","","G"]
Present Just "eF" PresentT (Just "eF")
>>>
pz @(Lookup Id 20) ["abc","D","eF","","G"]
Present Nothing PresentT Nothing
type LookupDef x y p = LookupDef' x y p I Source #
type LookupFail msg x y = LookupFail' msg x y I Source #
similar to cons
>>>
pz @(Fst Id :+ Snd Id) (99,[1,2,3,4])
Present [99,1,2,3,4] PresentT [99,1,2,3,4]
>>>
pz @(Snd Id :+ Fst Id) ([],5)
Present [5] PresentT [5]
>>>
pz @(123 :+ EmptyList _) "somestuff"
Present [123] PresentT [123]
similar to snoc
>>>
pz @(Snd Id +: Fst Id) (99,[1,2,3,4])
Present [1,2,3,4,99] PresentT [1,2,3,4,99]
>>>
pz @(Fst Id +: Snd Id) ([],5)
Present [5] PresentT [5]
>>>
pz @(EmptyT [] Id +: 5) 5
Present [5] PresentT [5]
uncons
>>>
pz @Uncons [1,2,3,4]
Present Just (1,[2,3,4]) PresentT (Just (1,[2,3,4]))
>>>
pz @Uncons []
Present Nothing PresentT Nothing
>>>
pz @Uncons (Seq.fromList "abc")
Present Just ('a',fromList "bc") PresentT (Just ('a',fromList "bc"))
>>>
pz @Uncons ("xyz" :: T.Text)
Present Just ('x',"yz") PresentT (Just ('x',"yz"))
unsnoc
>>>
pz @Unsnoc [1,2,3,4]
Present Just ([1,2,3],4) PresentT (Just ([1,2,3],4))
>>>
pz @Unsnoc []
Present Nothing PresentT Nothing
>>>
pz @Unsnoc ("xyz" :: T.Text)
Present Just ("xy",'z') PresentT (Just ("xy",'z'))
takes the head of a list like container
>>>
pz @(Head Id) "abcd"
Present 'a' PresentT 'a'
>>>
pz @(Head Id) []
Error Head(empty) FailT "Head(empty)"
takes the tail of a list like container
>>>
pz @(Tail Id) "abcd"
Present "bcd" PresentT "bcd"
>>>
pz @(Tail Id) []
Error Tail(empty) FailT "Tail(empty)"
takes the init of a list like container
>>>
pz @(Init Id) "abcd"
Present "abc" PresentT "abc"
>>>
pz @(Init Id) (T.pack "abcd")
Present "abc" PresentT "abc"
>>>
pz @(Init Id) []
Error Init(empty) FailT "Init(empty)"
takes the last of a list like container
>>>
pz @(Last Id) "abcd"
Present 'd' PresentT 'd'
>>>
pz @(Last Id) []
Error Last(empty) FailT "Last(empty)"
type HeadDef p q = JustDef p (q >> (Uncons >> FMapFst)) Source #
takes the head or default of a list-like object
see ConsT
for other supported types eg Seq
>>>
pz @(HeadDef 444 Id) []
Present 444 PresentT 444
>>>
pz @(HeadDef 444 Id) [1..5]
Present 1 PresentT 1
>>>
pz @(HeadDef 444 Id) [1..5]
Present 1 PresentT 1
>>>
pz @(HeadDef (Char1 "w") Id) (Seq.fromList "abcdef")
Present 'a' PresentT 'a'
>>>
pz @(HeadDef (Char1 "w") Id) Seq.empty
Present 'w' PresentT 'w'
>>>
pz @(HeadDef (MEmptyT _) Id) ([] @(SG.Sum _))
Present Sum {getSum = 0} PresentT (Sum {getSum = 0})
>>>
pz @(HeadDef (MEmptyT _) '[ "abc","def","asdfadf" ]) ()
Present "abc" PresentT "abc"
>>>
pz @(HeadDef (MEmptyT _) (Snd Id)) (123,[ "abc","def","asdfadf" ])
Present "abc" PresentT "abc"
>>>
pz @(HeadDef (MEmptyT _) (Snd Id)) (123,[])
Present () PresentT ()
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]
Present ("ac",[2,4,99],[('z',1),('a',2)]) 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] :: Type Source # eval :: MonadEval m => Proxy PartitionThese -> POpts -> [These a b] -> m (TT (PP PartitionThese [These a b])) Source # | |
type PP PartitionThese [These a b] Source # | |
Defined in Predicate.Prelude |
type Thiss = Fst PartitionThese Source #
type Thats = Snd PartitionThese Source #
type Theses = Thd PartitionThese Source #
This
constructor
>>>
pz @(MkThis _ Id) 44
Present This 44 PresentT (This 44)
>>>
pz @(Proxy Int >> MkThis' Unproxy 10) []
Present This 10 PresentT (This 10)
That
constructor
>>>
pz @(MkThat _ Id) 44
Present That 44 PresentT (That 44)
These
constructor
>>>
pz @(MkThese (Fst Id) (Snd Id)) (44,'x')
Present These 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)
Present 102 % 5 PresentT (102 % 5)
>>>
pz @(ThisDef (1 % 4) Id) (That "aa")
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(ThisDef (1 % 4) Id) (These 2.3 "aa")
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(ThisDef (PrintT "found %s fst=%d" '(ShowP (Snd Id), Fst Id)) (Snd Id)) (123,That "xy")
Present "found That \"xy\" fst=123" PresentT "found That \"xy\" fst=123"
>>>
pz @(ThisDef (MEmptyT _) Id) (That 222)
Present () PresentT ()
>>>
pz @(ThisDef (MEmptyT (SG.Sum _)) Id) (These 222 'x')
Present Sum {getSum = 0} PresentT (Sum {getSum = 0})
extract the This value from a These
otherwise fail with an error message
if there is no This value then p is passed the whole context only
>>>
pz @(ThisFail "oops" Id) (This 20.4)
Present 20.4 PresentT 20.4
>>>
pz @(ThisFail "oops" Id) (That "aa")
Error oops FailT "oops"
>>>
pz @(ThisFail (PrintT "found %s fst=%d" '(ShowP (Snd Id),Fst Id)) (Snd Id)) (123,That "xy")
Error found That "xy" fst=123 FailT "found That \"xy\" fst=123"
>>>
pz @(ThisFail (MEmptyT _) Id) (That 222)
Error 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)
Present 102 % 5 PresentT (102 % 5)
>>>
pz @(ThatDef (1 % 4) Id) (This "aa")
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(ThatDef (1 % 4) Id) (These "aa" 2.3)
Present 1 % 4 PresentT (1 % 4)
>>>
pz @(ThatDef (PrintT "found %s fst=%d" '(ShowP (Snd Id), Fst Id)) (Snd Id)) (123,This "xy")
Present "found This \"xy\" fst=123" PresentT "found This \"xy\" fst=123"
>>>
pz @(ThatDef (MEmptyT _) Id) (This 222)
Present () PresentT ()
>>>
pz @(ThatDef (MEmptyT (SG.Sum _)) Id) (These 'x' 1120)
Present Sum {getSum = 0} PresentT (Sum {getSum = 0})
extract the That value from a These
otherwise fail with an error message
if there is no That value then p is passed the whole context only
>>>
pz @(ThatFail "oops" Id) (That 20.4)
Present 20.4 PresentT 20.4
>>>
pz @(ThatFail "oops" Id) (This "aa")
Error oops FailT "oops"
>>>
pz @(ThatFail (PrintT "found %s fst=%d" '(ShowP (Snd Id),Fst Id)) (Snd Id)) (123,This "xy")
Error found This "xy" fst=123 FailT "found This \"xy\" fst=123"
>>>
pz @(ThatFail (MEmptyT _) Id) (This 222)
Error 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")
Present (102 % 5,"x") PresentT (102 % 5,"x")
>>>
pz @(TheseDef '(1 % 4,"zz") Id) (This 20.4)
Present (1 % 4,"zz") PresentT (1 % 4,"zz")
>>>
pz @(TheseDef '(1 % 4,"zz") Id) (That "x")
Present (1 % 4,"zz") PresentT (1 % 4,"zz")
>>>
pz @(TheseDef '(PrintT "found %s fst=%d" '(ShowP (Snd Id), Fst Id),999) (Snd Id)) (123,This "xy")
Present ("found This \"xy\" fst=123",999) PresentT ("found This \"xy\" fst=123",999)
>>>
pz @(TheseDef (MEmptyT (SG.Sum _, String)) Id) (This 222)
Present (Sum {getSum = 0},"") PresentT (Sum {getSum = 0},"")
>>>
pz @(TheseDef (MEmptyT _) Id) (These (222 :: SG.Sum Int) "aa")
Present (Sum {getSum = 222},"aa") PresentT (Sum {getSum = 222},"aa")
extract the These value from a These
otherwise fail with an error message
if there is no These value then p is passed the whole context only
>>>
pz @(TheseFail "oops" Id) (These "abc" 20.4)
Present ("abc",20.4) PresentT ("abc",20.4)
>>>
pz @(TheseFail "oops" Id) (That "aa")
Error oops FailT "oops"
>>>
pz @(TheseFail (PrintT "found %s fst=%d" '(ShowP (Snd Id),Fst Id)) (Snd Id)) (123,That "xy")
Error found That "xy" fst=123 FailT "found That \"xy\" fst=123"
>>>
pz @(TheseFail (MEmptyT _) Id) (That 222)
Error FailT ""
similar to these
>>>
pz @(TheseIn Id Len (Fst Id + Length (Snd Id))) (This 13)
Present 13 PresentT 13
>>>
pz @(TheseIn Id Len (Fst Id + Length (Snd Id))) (That "this is a long string")
Present 21 PresentT 21
>>>
pz @(TheseIn Id Len (Fst Id + Length (Snd Id))) (These 20 "somedata")
Present 28 PresentT 28
>>>
pz @(TheseIn (MkLeftAlt _ Id) (MkRightAlt _ Id) (If (Fst Id > Length (Snd Id)) (MkLeft _ (Fst Id)) (MkRight _ (Snd Id)))) (That "this is a long string")
Present Right "this is a long string" PresentT (Right "this is a long string")
>>>
pz @(TheseIn (MkLeftAlt _ Id) (MkRightAlt _ Id) (If (Fst Id > Length (Snd Id)) (MkLeft _ (Fst Id)) (MkRight _ (Snd Id)))) (These 1 "this is a long string")
Present Right "this is a long string" PresentT (Right "this is a long string")
>>>
pz @(TheseIn (MkLeftAlt _ Id) (MkRightAlt _ Id) (If (Fst Id > Length (Snd Id)) (MkLeft _ (Fst Id)) (MkRight _ (Snd Id)))) (These 100 "this is a long string")
Present Left 100 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)
Present "132" PresentT "132"
>>>
pz @(TheseX '(Snd Id,"fromthis") '(Negate 99,Snd Id) (Snd Id) Id) (This 123)
Present (123,"fromthis") PresentT (123,"fromthis")
>>>
pz @(TheseX '(Snd Id,"fromthis") '(Negate 99,Snd Id) (Snd Id) Id) (That "fromthat")
Present (-99,"fromthat") PresentT (-99,"fromthat")
>>>
pz @(TheseX '(Snd Id,"fromthis") '(Negate 99,Snd Id) (Snd Id) Id) (These 123 "fromthese")
Present (123,"fromthese") PresentT (123,"fromthese")
fold / unfold expressions
similar to scanl
>>>
pz @(Scanl (Snd Id :+ Fst Id) (Fst Id) (Snd Id)) ([99],[1..5])
Present [[99],[1,99],[2,1,99],[3,2,1,99],[4,3,2,1,99],[5,4,3,2,1,99]] 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'
Present "cdefg" PresentT "cdefg"
>>>
pz @(FoldN 4 Id (Succ Id)) 'c'
Present 'g' PresentT 'g'
similar to unfoldr
>>>
pz @(Unfoldr (MaybeBool (Not Null) (SplitAt 2 Id)) Id) [1..5]
Present [[1,2],[3,4],[5]] PresentT [[1,2],[3,4],[5]]
>>>
pz @(IterateN 4 (Succ Id)) 4
Present [4,5,6,7] PresentT [4,5,6,7]
type IterateUntil p f = IterateWhile (Not p) f Source #
type IterateNWhile n p f = '(n, Id) >> (IterateWhile ((Fst Id > 0) && (Snd Id >> p)) (Pred Id *** f) >> Map (Snd Id) Id) Source #
type IterateNUntil n p f = IterateNWhile n (Not p) f Source #
failure expressions
Fails the computation with a message
>>>
pz @(Failt Int (PrintF "value=%03d" Id)) 99
Error value=099 FailT "value=099"
>>>
pz @(FailS (PrintT "value=%03d string=%s" Id)) (99,"somedata")
Error value=099 string=somedata FailT "value=099 string=somedata"
catch a failure
>>>
pz @(Catch (Succ Id) (Fst Id >> Second (ShowP Id) >> PrintT "%s %s" Id >> 'LT)) GT
Present LT PresentT LT
>>>
pz @(Catch' (Succ Id) (Second (ShowP Id) >> PrintT "%s %s" Id)) GT
Error Succ IO e=Prelude.Enum.Ordering.succ: bad argument GT FailT "Succ IO e=Prelude.Enum.Ordering.succ: bad argument GT"
>>>
pz @(Catch' (Succ Id) (Second (ShowP Id) >> PrintT "%s %s" Id)) LT
Present EQ PresentT EQ
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])
Present [These 'a' 1,These 'B' 2,These 'c' 3,That 4,That 5] PresentT [These 'a' 1,These 'B' 2,These 'c' 3,That 4,That 5]
>>>
pz @(ZipThese (Fst Id) (Snd Id)) ("aBcDeF", [1..3])
Present [These 'a' 1,These 'B' 2,These 'c' 3,This 'D',This 'e',This 'F'] PresentT [These 'a' 1,These 'B' 2,These 'c' 3,This 'D',This 'e',This 'F']
>>>
pz @(ZipThese Id Reverse) "aBcDeF"
Present [These 'a' 'F',These 'B' 'e',These 'c' 'D',These 'D' 'c',These 'e' 'B',These 'F' 'a'] PresentT [These 'a' 'F',These 'B' 'e',These 'c' 'D',These 'D' 'c',These 'e' 'B',These 'F' 'a']
>>>
pz @(ZipThese Id '[]) "aBcDeF"
Present [This 'a',This 'B',This 'c',This 'D',This 'e',This 'F'] PresentT [This 'a',This 'B',This 'c',This 'D',This 'e',This 'F']
>>>
pz @(ZipThese '[] Id) "aBcDeF"
Present [That 'a',That 'B',That 'c',That 'D',That 'e',That 'F'] PresentT [That 'a',That 'B',That 'c',That 'D',That 'e',That 'F']
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 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 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 FailT "Zip(3,2) length mismatch"
>>>
pl @(Zip '[1,2] "abc") ()
Error Zip(2,3) length mismatch FailT "Zip(2,3) length mismatch"
type Unzip = '(Map (Fst Id) Id, Map (Snd Id) Id) Source #
unzip
equivalent
>>>
pz @Unzip (zip [1..5] "abcd")
Present ([1,2,3,4],"abcd") PresentT ([1,2,3,4],"abcd")
type Unzip3 = '(Map (Fst Id) Id, Map (Snd Id) Id, Map (Thd Id) Id) Source #
unzip3
equivalent
>>>
pz @Unzip3 (zip3 [1..5] "abcd" (cycle [True,False]))
Present ([1,2,3,4],"abcd",[True,False,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
Present "greater than 4" PresentT "greater than 4"
>>>
pz @(If (Gt 4) "greater than 4" "less than or equal to 4") 0
Present "less than or equal to 4" PresentT "less than or equal to 4"
data Case (e :: k0) (ps :: [k]) (qs :: [k1]) (r :: k2) Source #
type Case' (ps :: [k]) (qs :: [k1]) (r :: k2) = Case (Snd Id >> Failp "Case:no match") ps qs r Source #
type GuardsQuick (prt :: k) (os :: [k1]) = Guards (ToGuardsT prt os) Source #
'p' is the predicate and on failure of the predicate runs 'prt'
>>>
pz @(Guard "expected > 3" (Gt 3)) 17
Present 17 PresentT 17
>>>
pz @(Guard "expected > 3" (Gt 3)) 1
Error expected > 3 FailT "expected > 3"
>>>
pz @(Guard (PrintF "%d not > 3" Id) (Gt 3)) (-99)
Error -99 not > 3 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 using ol
and a boolean predicate unless you require failure on error
>>>
pz @(GuardSimple (Luhn Id)) [1..4]
Error (Luhn map=[4,6,2,2] sum=14 ret=4 | [1,2,3,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]
Present [1,2,3,0] PresentT [1,2,3,0]
>>>
pz @(GuardSimple (Len > 30)) [1,2,3,0]
Error (4 > 30) 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)) [121,33,7,256]
Error id=4 must be between 0 and 255, found 256 FailT "id=4 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)) [121,33,7,44]
Present [121,33,7,44] PresentT [121,33,7,44]
type GuardsDetail (prt :: Symbol) (os :: [(k0, k1)]) = GuardsImplXX (ToGuardsDetailT prt os) Source #
data Bools (ps :: [(k, k1)]) Source #
boolean guard which checks a given a list of predicates against the list of values
pulls the top message from the tree if a predicate is false
>>>
pl @(Bools '[ '(W "hh",Between 0 23), '(W "mm",Between 0 59), '(PrintT "<<<%d %d>>>" Id,Between 0 59) ] ) [12,93,14]
False (GuardBool(1) [mm] (93 <= 59)) FalseT
>>>
pl @(Bools '[ '(W "hh",Between 0 23), '(W "mm",Between 0 59), '(PrintT "<<<%d %d>>>" Id,Between 0 59) ] ) [12,13,94]
False (GuardBool(2) [<<<2 94>>>] (94 <= 59)) FalseT
>>>
pl @(Bools '[ '(W "hh",Between 0 23), '(W "mm",Between 0 59), '(PrintT "<<<%d %d>>>" Id,Between 0 59) ] ) [12,13,14]
True (GuardBool(0) 12) TrueT
>>>
pl @(BoolsQuick "abc" '[Between 0 23, Between 0 59, Between 0 59]) [12,13,14]
True (GuardBool(0) 12) TrueT
>>>
pl @(BoolsQuick (PrintT "id=%d val=%d" Id) '[Between 0 23, Between 0 59, Between 0 59]) [12,13,14]
True (GuardBool(0) 12) TrueT
>>>
pl @(BoolsQuick (PrintT "id=%d val=%d" Id) '[Between 0 23, Between 0 59, Between 0 59]) [12,13,99]
False (GuardBool(2) [id=2 val=99] (99 <= 59)) FalseT
type BoolsQuick (prt :: k) (ps :: [k1]) = Bools (ToGuardsT prt ps) Source #
data BoolsN prt (n :: Nat) p 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)) [121,33,7,256]
False (GuardBool(3) [id=3 must be between 0 and 255, found 256] (256 <= 255)) FalseT
>>>
pz @(GuardsN (PrintT "id=%d must be between 0 and 255, found %d" Id) 4 (Between 0 255)) [121,33,7,44]
Present [121,33,7,44] PresentT [121,33,7,44]
Instances
(GetLen (ToGuardsT prt (RepeatT n p)), PP (BoolsImpl (LenT (ToGuardsT prt (RepeatT n p))) (ToGuardsT prt (RepeatT n p))) [a] ~ Bool, P (BoolsImpl (LenT (ToGuardsT prt (RepeatT n p))) (ToGuardsT prt (RepeatT n p))) [a]) => P (BoolsN prt n p :: Type) [a] Source # | |
type PP (BoolsN prt n p :: Type) [a] Source # | |
Defined in Predicate.Prelude |
IO expressions
similar to readFile
>>>
pz @(ReadFile ".ghci" >> 'Just Id >> Len > 0) ()
True TrueT
>>>
pz @(FileExists "xyzzy") ()
False FalseT
does the directory exists
>>>
pz @(DirExists ".") ()
True TrueT
does the directory exists
>>>
pz @(ReadEnv "PATH" >> 'Just Id >> 'True) ()
True TrueT
data ReadEnvAll Source #
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 |
type AppendFile (s :: Symbol) p = WriteFileImpl (FOther s WFAppend) p Source #
type WriteFile' (s :: Symbol) p = WriteFileImpl (FOther s WFWriteForce) p Source #
string expressions
converts a string IsText
value to lower case
>>>
pz @ToLower "HeLlO wOrld!"
Present "hello world!" PresentT "hello world!"
converts a string IsText
value to upper case
>>>
pz @ToUpper "HeLlO wOrld!"
Present "HELLO WORLD!" PresentT "HELLO WORLD!"
data StripLR (right :: Bool) p q Source #
similar to stripLeft
stripRight
>>>
pz @(StripLeft "xyz" Id) ("xyzHello" :: String)
Present Just "Hello" PresentT (Just "Hello")
>>>
pz @(StripLeft "xyz" Id) (T.pack "xyzHello")
Present Just "Hello" PresentT (Just "Hello")
>>>
pz @(StripLeft "xyz" Id) "xywHello"
Present Nothing PresentT Nothing
>>>
pz @(StripRight "xyz" Id) "Hello xyz"
Present Just "Hello " PresentT (Just "Hello ")
>>>
pz @(StripRight "xyz" Id) "xyzHelloxyw"
Present Nothing PresentT Nothing
>>>
pz @(StripRight "xyz" Id) ""
Present Nothing PresentT Nothing
>>>
pz @(StripRight "xyz" "xyz") ()
Present Just "" PresentT (Just "")
type StripRight p q = StripLR True p q Source #
type FromStringP (t :: Type) p = FromStringP' (Hole t) p Source #
data FromStringP' t s Source #
fromString
function where you need to provide the type 't' of the result
>>>
pz @(FromStringP (Identity _) Id) "abc"
Present Identity "abc" PresentT (Identity "abc")
>>>
pz @(FromStringP (Seq.Seq _) Id) "abc"
Present fromList "abc" PresentT (fromList "abc")
Instances
(P s a, PP s a ~ String, Show (PP t a), IsString (PP t a)) => P (FromStringP' t s :: Type) a Source # | |
Defined in Predicate.Prelude type PP (FromStringP' t s) a :: Type Source # eval :: MonadEval m => Proxy (FromStringP' t s) -> POpts -> a -> m (TT (PP (FromStringP' t s) a)) Source # | |
type PP (FromStringP' t s :: Type) a Source # | |
Defined in Predicate.Prelude |
print expressions
uses PrintF to format output
>>>
pz @(PrintF "value=%03d" Id) 12
Present "value=012" PresentT "value=012"
>>>
pz @(PrintF "%s" (Fst Id)) ("abc",'x')
Present "abc" PresentT "abc"
>>>
pz @(PrintF "%d" (Fst Id)) ("abc",'x')
Error PrintF (IO e=printf: bad formatting char 'd') FailT "PrintF (IO e=printf: bad formatting char 'd')"
data PrintL (n :: Nat) s p Source #
print for lists -- if you can use PrintT
>>>
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"
>>>
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 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 FailT "PrintL(4) arg count=3"
print for flat n-tuples
>>>
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)
Present "fst=ab snd=123" PresentT "fst=ab snd=123"
>>>
pz @(PrintT "fst=%s snd=%03d thd=%s" Id) ("ab",123,"xx")
Present "fst=ab snd=123 thd=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) 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) 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
Present Just 4 PresentT (Just 4)
>>>
pz @(Pure [] Id) 4
Present [4] PresentT [4]
>>>
pz @(Pure (Either String) (Fst Id)) (13,True)
Present Right 13 PresentT (Right 13)
data Pure2 (t :: Type -> Type) Source #
lift pure over a Functor
>>>
pz @(Pure2 (Either String)) [1,2,4]
Present [Right 1,Right 2,Right 4] PresentT [Right 1,Right 2,Right 4]
type FoldMap (t :: Type) p = Map (Wrap t Id) p >> Unwrap (MConcat Id) Source #
similar to a limited form of foldMap
>>>
pz @(FoldMap (SG.Sum _) Id) [44, 12, 3]
Present 59 PresentT 59
>>>
pz @(FoldMap (SG.Product _) Id) [44, 12, 3]
Present 1584 PresentT 1584
>>>
type Ands' p = FoldMap SG.All p
>>>
pz @(Ands' Id) [True,False,True,True]
Present False PresentT False
>>>
pz @(Ands' Id) [True,True,True]
Present True PresentT True
>>>
pz @(Ands' Id) []
Present True PresentT True
>>>
type Ors' p = FoldMap SG.Any p
>>>
pz @(Ors' Id) [False,False,False]
Present False PresentT False
>>>
pz @(Ors' Id) []
Present False PresentT False
>>>
pz @(Ors' Id) [False,False,False,True]
Present True PresentT True
>>>
type AllPositive' = FoldMap SG.All (Map Positive Id)
>>>
pz @AllPositive' [3,1,-5,10,2,3]
Present False PresentT False
>>>
type AllNegative' = FoldMap SG.All (Map Negative Id)
>>>
pz @AllNegative' [-1,-5,-10,-2,-3]
Present True 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]
Present 12 PresentT 12
similar to <$
>>>
pz @(Fst Id <$ Snd Id) ("abc",Just 20)
Present Just "abc" PresentT (Just "abc")
type (*>) p q = q <* p infixl 4 Source #
similar to <*
>>>
pz @(Fst Id <* Snd Id) (Just "abc",Just 20)
Present Just "abc" PresentT (Just "abc")
similar to fmap fst
>>>
pz @FMapFst (Just (13,"Asf"))
Present Just 13 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))
Present Just 13 PresentT (Just 13)
similar to sequenceA
>>>
pz @Sequence [Just 10, Just 20, Just 30]
Present Just [10,20,30] PresentT (Just [10,20,30])
>>>
pz @Sequence [Just 10, Just 20, Just 30, Nothing, Just 40]
Present Nothing 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))
Present Just 20 PresentT (Just 20)
>>>
pz @Join ["ab","cd","","ef"]
Present "abcdef" PresentT "abcdef"
data EmptyT (t :: Type -> Type) p Source #
similar to empty
>>>
pz @(EmptyT Maybe Id) ()
Present Nothing PresentT Nothing
>>>
pz @(EmptyT [] Id) ()
Present [] PresentT []
>>>
pz @(EmptyT [] (Char1 "x")) (13,True)
Present "" PresentT ""
>>>
pz @(EmptyT (Either String) (Fst Id)) (13,True)
Present Left "" PresentT (Left "")
data p <|> q infixl 3 Source #
similar to <|>
>>>
pz @(Fst Id <|> Snd Id) (Nothing,Just 20)
Present Just 20 PresentT (Just 20)
>>>
pz @(Fst Id <|> Snd Id) (Just 10,Just 20)
Present Just 10 PresentT (Just 10)
>>>
pz @(Fst Id <|> Snd Id) (Nothing,Nothing)
Present Nothing PresentT Nothing
similar to extract
>>>
pz @Extract (Nothing,Just 20)
Present Just 20 PresentT (Just 20)
>>>
pz @Extract (Identity 20)
Present 20 PresentT 20
similar to duplicate
>>>
pz @Duplicate (20,"abc")
Present (20,(20,"abc")) PresentT (20,(20,"abc"))
expression combinators
function application for expressions: similar to $
pz @(Fst Id $ Snd Id) ((*16),4) Present 64 PresentT 64
pz @(Id $ "def") ("abc"<>) Present "abcdef" PresentT "abcdef"
flipped function application for expressions: similar to &
pz @(Snd Id & Fst Id) ((*16),4) Present 64 PresentT 64
pz @("def" & Id) ("abc"<>) Present "abcdef" PresentT "abcdef"
processes a type level list predicates running each in sequence: see >>
>>>
pz @(Do [Pred Id, ShowP Id, Id &&& Len]) 9876543
Present ("9876542",7) PresentT ("9876542",7)
>>>
pz @(Do '[W 123, W "xyz", Len &&& Id, Pred Id *** Id<>Id]) ()
Present (2,"xyzxyz") PresentT (2,"xyzxyz")
This is composition for predicates
>>>
pz @(Fst Id >> Succ (Id !! 0)) ([11,12],'x')
Present 12 PresentT 12
>>>
pz @(Len *** Succ Id >> ShowP (First (Pred Id))) ([11,12],'x')
Present "(1,'y')" 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'
Present 'g' PresentT 'g'
>>>
pz @(DoN 4 (Id <> " | ")) "abc"
Present "abc | | | | " PresentT "abc | | | | "
>>>
pz @(DoN 4 (Id <> "|" <> Id)) "abc"
Present "abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc" PresentT "abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc|abc"
parallel expressions
data ParaN (n :: Nat) p Source #
leverages Para
for repeating predicates (passthrough method)
>>>
pz @(ParaN 4 (Succ Id)) [1..4]
Present [2,3,4,5] PresentT [2,3,4,5]
>>>
pz @(ParaN 4 (Succ Id)) "azwxm"
Error Para: data elements(5) /= predicates(4) FailT "Para: data elements(5) /= predicates(4)"
>>>
pz @(ParaN 4 (Succ Id)) "azwx"
Present "b{xy" 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'
Present "dddd" PresentT "dddd"
>>>
pz @(Repeat 4 "abc") ()
Present ["abc","abc","abc","abc"] PresentT ["abc","abc","abc","abc"]
miscellaneous
a predicate on prime numbers
>>>
pz @(Prime Id) 2
True TrueT
>>>
pz @(Map '(Id,Prime Id) Id) [0..12]
Present [(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)] 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)]
Luhn predicate check on last digit
>>>
pz @(Luhn Id) [1,2,3,0]
True TrueT
>>>
pz @(Luhn Id) [1,2,3,4]
False FalseT
>>>
pz @(GuardSimple (Luhn Id)) [15,4,3,1,99]
Error (Luhn map=[90,2,3,8,6] sum=109 ret=9 | [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") ()
Present 'a' PresentT 'a'
run the expression 'p' but remove the subtrees