typed-encoding-0.5.2.1: Type safe string transformations

Safe HaskellSafe
LanguageHaskell2010

Data.TypedEncoding.Instances.Support.Bool

Description

Combinators for creating encoding using existing encodings.

Since: 0.4.2.0

Synopsis

Documentation

>>> :set -XDataKinds -XFlexibleInstances -XFlexibleContexts -XOverloadedStrings -XTypeApplications -XScopedTypeVariables
>>> import           Data.TypedEncoding
>>> import           Data.TypedEncoding.Instances.Restriction.BoundedAlphaNums (encFBan)

implEncOr' :: forall alg alg1 alg2 nm nm1 nm2 c str. KnownSymbol nm => Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm2 alg2 c str -> Encoding (Either EncodeEx) nm alg c str Source #

Defines new encoding by specifying 2 encodings, one needs to succeed.

Since: 0.4.2.0

implEncOr :: forall nm nm1 nm2 c str. KnownSymbol nm => Encoding (Either EncodeEx) nm1 nm1 c str -> Encoding (Either EncodeEx) nm2 nm2 c str -> Encoding (Either EncodeEx) nm nm c str Source #

_implEncOr :: forall nm nm1 nm2 c str alg alg1 alg2. (KnownSymbol nm, Algorithm nm alg, Algorithm nm1 alg1, Algorithm nm2 alg2) => Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm2 alg2 c str -> Encoding (Either EncodeEx) nm alg c str Source #

>>> let tst = _implEncOr @"r-tst:999(9)" @"r-ban:9999" @"r-ban:999" @() @String encFBan encFBan
>>> fmap displ $ _runEncoding tst $ toEncoding () "123"
Right "Enc '[r-tst:999(9)] () (String 123)"
>>> fmap displ $ _runEncoding tst $ toEncoding () "1234"
Right "Enc '[r-tst:999(9)] () (String 1234)"
>>> fmap displ $ _runEncoding tst $ toEncoding () "12345"
Left (EncodeEx "r-tst:999(9)" (("Input list has wrong size expecting 4 but length \"12345\" == 5","Input list has wrong size expecting 3 but length \"12345\" == 5")))

Since: 0.4.2.0

implEncAnd' :: forall alg alg1 alg2 nm nm1 nm2 c str. (KnownSymbol nm, Eq str) => Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm2 alg2 c str -> Encoding (Either EncodeEx) nm alg c str Source #

Defines new encoding by specifying 2 encodings, both needs to succeed and produce the same payload.

Since: 0.4.2.0

implEncAnd :: forall nm nm1 nm2 c str. (KnownSymbol nm, Eq str) => Encoding (Either EncodeEx) nm1 nm1 c str -> Encoding (Either EncodeEx) nm2 nm2 c str -> Encoding (Either EncodeEx) nm nm c str Source #

_implEncAnd :: forall nm nm1 nm2 c str alg alg1 alg2. (KnownSymbol nm, Eq str, Algorithm nm alg, Algorithm nm1 alg1, Algorithm nm2 alg2) => Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm2 alg2 c str -> Encoding (Either EncodeEx) nm alg c str Source #

>>> let tst2 = _implEncAnd @"r-tst:99" @"r-ban:9Z" @"r-ban:Z9" @() @String encFBan encFBan
>>> fmap displ $ _runEncoding tst2 $ toEncoding () "99"
Right "Enc '[r-tst:99] () (String 99)"
>>> fmap displ $ _runEncoding tst2 $ toEncoding () "AB"
Left (EncodeEx "r-tst:99" (("'A' not bounded by '9'","'B' not bounded by '9'")))

Since: 0.4.2.0

implEncNot' :: forall alg alg1 nm nm1 c str. KnownSymbol nm => (str -> str) -> Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm alg c str Source #

Defines new encoding which succeeds only if specified encoding fails. It that happens, it applies given transformation function.

Since: 0.4.2.0

implEncNot :: forall nm nm1 c str. KnownSymbol nm => (str -> str) -> Encoding (Either EncodeEx) nm1 nm1 c str -> Encoding (Either EncodeEx) nm nm c str Source #

_implEncNot :: forall nm nm1 c str alg alg1. (KnownSymbol nm, Algorithm nm alg, Algorithm nm1 alg1) => (str -> str) -> Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm alg c str Source #

_implREncNot :: forall nm nm1 c str alg alg1. (KnownSymbol nm, Algorithm nm alg, Algorithm nm1 alg1) => Encoding (Either EncodeEx) nm1 alg1 c str -> Encoding (Either EncodeEx) nm alg c str Source #

Defines restriction encoding that succeeds when specified encoding fails

>>> let tst3 = _implREncNot @"r-tstnot:99" @"r-ban:99" @() @String encFBan
>>> fmap displ $ _runEncoding tst3 $ toEncoding () "AA"
Right "Enc '[r-tstnot:99] () (String AA)"
>>> fmap displ $ _runEncoding tst3 $ toEncoding () "99"
Left (EncodeEx "r-tstnot:99" ("Negated encoding succeeded"))

Since: 0.4.2.0