superrecord-0.5.1.0: Supercharged anonymous records

Safe HaskellNone
LanguageHaskell2010

SuperRecord.Variant.Text

Synopsis

Documentation

data TextVariant (opts :: [Symbol]) Source #

A text only variant: A wrapped Text that can only be one of the given values tracked at type level. Very useful for interacting with enum-like string in JSON APIs.

Instances
Eq (TextVariant opts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

Methods

(==) :: TextVariant opts -> TextVariant opts -> Bool #

(/=) :: TextVariant opts -> TextVariant opts -> Bool #

Ord (TextVariant opts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

Methods

compare :: TextVariant opts -> TextVariant opts -> Ordering #

(<) :: TextVariant opts -> TextVariant opts -> Bool #

(<=) :: TextVariant opts -> TextVariant opts -> Bool #

(>) :: TextVariant opts -> TextVariant opts -> Bool #

(>=) :: TextVariant opts -> TextVariant opts -> Bool #

max :: TextVariant opts -> TextVariant opts -> TextVariant opts #

min :: TextVariant opts -> TextVariant opts -> TextVariant opts #

Show (TextVariant opts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

Methods

showsPrec :: Int -> TextVariant opts -> ShowS #

show :: TextVariant opts -> String #

showList :: [TextVariant opts] -> ShowS #

ToJSON (TextVariant opts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

TextVariantBuilder opts => FromJSON (TextVariant opts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

NFData (TextVariant opts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

Methods

rnf :: TextVariant opts -> () #

type family TextVariantMember (lbl :: Symbol) (opts :: [Symbol]) where ... Source #

Equations

TextVariantMember lbl (lbl ': xs) = True ~ True 
TextVariantMember lbl (lbl1 ': ys) = TextVariantMember lbl ys 

emptyTextVariant :: TextVariant '[] Source #

An empty TextVariant, equivalent to `()`

toTextVariant :: forall opts lbl. (KnownSymbol lbl, TextVariantMember lbl opts) => FldProxy lbl -> TextVariant opts Source #

Create a TextVariant value from a statically known string. Use OverloadedLabels for nice syntax: toTextVariant #myString

fromTextVariant :: TextVariant opts -> Text Source #

Convert a TextVariant back to a normal Text. This operation is cheap since TextVariant is a simple newtype.

data TextVariantMatch r ts where Source #

Constructors

TextVariantCase :: FldProxy lbl -> r -> TextVariantMatch r ts -> TextVariantMatch r (lbl ': ts) 
TextVariantEnd :: TextVariantMatch r '[] 
TextVariantWildCard :: r -> TextVariantMatch r ts 

class TextVariantMatcher r opts where Source #

Pattern matching helper with totality check. Note that the performance of this pattern match is roughly like a normal pattern match. (See benchmarks)

Methods

textVariantMatch :: TextVariant opts -> TextVariantMatch r opts -> r Source #

Instances
TextVariantMatcher r ([] :: [Symbol]) Source # 
Instance details

Defined in SuperRecord.Variant.Text

(KnownSymbol lbl, TextVariantMatcher r ts) => TextVariantMatcher r (lbl ': ts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

Methods

textVariantMatch :: TextVariant (lbl ': ts) -> TextVariantMatch r (lbl ': ts) -> r Source #

class TextVariantBuilder opts where Source #

Build a variant from a text that is not statically known at compile time. Returns Nothing on failure (i.E. when a value is given that is not part of the variant)

Instances
TextVariantBuilder ([] :: [Symbol]) Source # 
Instance details

Defined in SuperRecord.Variant.Text

(KnownSymbol lbl, TextVariantBuilder ts) => TextVariantBuilder (lbl ': ts) Source # 
Instance details

Defined in SuperRecord.Variant.Text

Methods

buildTextVariant :: Text -> Maybe (TextVariant (lbl ': ts)) Source #