typed-encoding-0.5.0.0: Type safe string transformations

Safe HaskellSafe
LanguageHaskell2010

Data.TypedEncoding.Common.Class.Encode

Description

Type classes accompanying decoding types defined in Data.TypedEncoding.Common.Types.Enc

Examples.TypedEncoding.Instances.DiySignEncoding contains an implementation example.

Examples.TypedEncoding.Overview shows decoding usage examples.

This module is re-exported in Data.TypedEncoding and it is best not to import it directly.

Synopsis

Documentation

class Encode f nm alg conf str where Source #

Using 2 Symbol type variables (nm and alg) creates what seems like redundant typing in statically defined instances such as "r-ASCII", however it provides future flexibility to constrain nm in some interesting way, different than AlgNm nm ~ alg.

It also seems to be easier to understand as type variables used in the definition of Encoding match with what is on the typeclass.

alg is expected to be very statically defined and is needed to support more open instances such as "r-ban".

Since: 0.3.0.0

Methods

encoding :: Encoding f nm alg conf str Source #

Instances
Applicative f => Encode f "enc-B64" "enc-B64" c Text Source #

This instance will likely be removed in future versions (performance concerns) (Moved from Data.TypedEncoding.Instances.Enc.Base64)

Instance details

Defined in Data.TypedEncoding.Instances.Enc.Warn.Base64

Methods

encoding :: Encoding f "enc-B64" "enc-B64" c Text Source #

Applicative f => Encode f "enc-B64" "enc-B64" c ByteString Source #

Since: 0.3.0.0

Instance details

Defined in Data.TypedEncoding.Instances.Enc.Base64

Methods

encoding :: Encoding f "enc-B64" "enc-B64" c ByteString Source #

Applicative f => Encode f "enc-B64" "enc-B64" c ByteString Source #

Since: 0.3.0.0

Instance details

Defined in Data.TypedEncoding.Instances.Enc.Base64

Methods

encoding :: Encoding f "enc-B64" "enc-B64" c ByteString Source #

Applicative f => Encode f "my-sign" "my-sign" c Text Source #

Because encoding function is pure we can create instance of Encode that is polymorphic in effect f.

This is done using implTranP combinator.

Instance details

Defined in Examples.TypedEncoding.Instances.DiySignEncoding

Methods

encoding :: Encoding f "my-sign" "my-sign" c Text Source #

(HasA SizeLimit c, Applicative f) => Encode f "do-size-limit" "do-size-limit" c ByteString Source # 
Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-size-limit" "do-size-limit" c ByteString Source #

(HasA SizeLimit c, Applicative f) => Encode f "do-size-limit" "do-size-limit" c Text Source #

Since: 0.3.0.0

Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-size-limit" "do-size-limit" c Text Source #

Applicative f => Encode f "do-reverse" "do-reverse" c Text Source # 
Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-reverse" "do-reverse" c Text Source #

Applicative f => Encode f "do-reverse" "do-reverse" c Text Source #

Since: 0.3.0.0

Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-reverse" "do-reverse" c Text Source #

Applicative f => Encode f "do-Title" "do-Title" c Text Source # 
Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-Title" "do-Title" c Text Source #

Applicative f => Encode f "do-Title" "do-Title" c Text Source #

Since: 0.3.0.0

Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-Title" "do-Title" c Text Source #

Applicative f => Encode f "do-lower" "do-lower" c Text Source # 
Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-lower" "do-lower" c Text Source #

Applicative f => Encode f "do-lower" "do-lower" c Text Source #

Since: 0.3.0.0

Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-lower" "do-lower" c Text Source #

Applicative f => Encode f "do-UPPER" "do-UPPER" c Text Source # 
Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-UPPER" "do-UPPER" c Text Source #

Applicative f => Encode f "do-UPPER" "do-UPPER" c Text Source #

Since: 0.3.0.0

Instance details

Defined in Examples.TypedEncoding.Instances.Do.Sample

Methods

encoding :: Encoding f "do-UPPER" "do-UPPER" c Text Source #

(Ban s, Algorithm s "r-ban", IsStringR str) => Encode (Either EncodeEx) s "r-ban" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.BoundedAlphaNums

Methods

encoding :: Encoding (Either EncodeEx) s "r-ban" c str Source #

Char8Find str => Encode (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ASCII

Methods

encoding :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source #

Encode (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ASCII

Methods

encoding :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source #

Encode (Either EncodeEx) "r-ByteRep" "r-ByteRep" c String Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ByteRep

Methods

encoding :: Encoding (Either EncodeEx) "r-ByteRep" "r-ByteRep" c String Source #

Encode (Either EncodeEx) "r-ByteRep" "r-ByteRep" c ByteString Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ByteRep

Methods

encoding :: Encoding (Either EncodeEx) "r-ByteRep" "r-ByteRep" c ByteString Source #

Encode (Either EncodeEx) "r-ByteRep" "r-ByteRep" c ByteString Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ByteRep

Methods

encoding :: Encoding (Either EncodeEx) "r-ByteRep" "r-ByteRep" c ByteString Source #

Encode (Either EncodeEx) "r-ByteRep" "r-ByteRep" c Char Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ByteRep

Methods

encoding :: Encoding (Either EncodeEx) "r-ByteRep" "r-ByteRep" c Char Source #

IsStringR str => Encode (Either EncodeEx) "r-Int-decimal" "r-Int-decimal" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.Misc

Methods

encoding :: Encoding (Either EncodeEx) "r-Int-decimal" "r-Int-decimal" c str Source #

Encode (Either EncodeEx) "r-UNICODE.D76" "r-UNICODE.D76" c String Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.D76

Methods

encoding :: Encoding (Either EncodeEx) "r-UNICODE.D76" "r-UNICODE.D76" c String Source #

Encode (Either EncodeEx) "r-UNICODE.D76" "r-UNICODE.D76" c Char Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.D76

Methods

encoding :: Encoding (Either EncodeEx) "r-UNICODE.D76" "r-UNICODE.D76" c Char Source #

Encode (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.UTF8

Methods

encoding :: Encoding (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source #

Encode (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source #

UTF8 encodings are defined for ByteString only as that would not make much sense for Text

>>> encodeFAll . toEncoding () $ "\xc3\xb1" :: Either EncodeEx (Enc '["r-UTF8"] () B.ByteString)
Right (UnsafeMkEnc Proxy () "\195\177")
>>> encodeFAll . toEncoding () $ "\xc3\x28" :: Either EncodeEx (Enc '["r-UTF8"] () B.ByteString)
Left (EncodeEx "r-UTF8" (Cannot decode byte '\xc3': ...

Following test uses verEncoding helper that checks that bytes are encoded as Right iff they are valid UTF8 bytes

>>> :{
quickCheck $ \(b :: B.ByteString) -> verEncoding b $ fmap (
         fromEncoding 
         . decodeAll @'["r-UTF8"]
         ) . encodeFAll @'["r-UTF8"] @(Either EncodeEx)
         . toEncoding () $ b
:}
+++ OK, passed 100 tests.
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.UTF8

Methods

encoding :: Encoding (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source #

IsStringR str => Encode (Either EncodeEx) "r-Word8-decimal" "r-Word8-decimal" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.Misc

Methods

encoding :: Encoding (Either EncodeEx) "r-Word8-decimal" "r-Word8-decimal" c str Source #

class EncodeAll f nms algs conf str where Source #

Since: 0.3.0.0

Methods

encodings :: Encodings f nms algs conf str Source #

Instances
EncodeAll f ([] :: [Symbol]) ([] :: [Symbol]) conf str Source # 
Instance details

Defined in Data.TypedEncoding.Common.Class.Encode

Methods

encodings :: Encodings f [] [] conf str Source #

(EncodeAll f nms algs conf str, Encode f nm alg conf str) => EncodeAll f (nm ': nms) (alg ': algs) conf str Source # 
Instance details

Defined in Data.TypedEncoding.Common.Class.Encode

Methods

encodings :: Encodings f (nm ': nms) (alg ': algs) conf str Source #