Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data TextVariant (opts :: [Symbol])
- type family TextVariantMember (lbl :: Symbol) (opts :: [Symbol]) where ...
- emptyTextVariant :: TextVariant '[]
- toTextVariant :: forall opts lbl. (KnownSymbol lbl, TextVariantMember lbl opts) => FldProxy lbl -> TextVariant opts
- fromTextVariant :: TextVariant opts -> Text
- data TextVariantMatch r ts where
- TextVariantCase :: FldProxy lbl -> r -> TextVariantMatch r ts -> TextVariantMatch r (lbl ': ts)
- TextVariantEnd :: TextVariantMatch r '[]
- TextVariantWildCard :: r -> TextVariantMatch r ts
- class TextVariantMatcher r opts where
- textVariantMatch :: TextVariant opts -> TextVariantMatch r opts -> r
- class TextVariantBuilder opts where
- buildTextVariant :: Text -> Maybe (TextVariant opts)
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
type family TextVariantMember (lbl :: Symbol) (opts :: [Symbol]) where ... Source #
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 #
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)
textVariantMatch :: TextVariant opts -> TextVariantMatch r opts -> r Source #
Instances
TextVariantMatcher r ([] :: [Symbol]) Source # | |
Defined in SuperRecord.Variant.Text textVariantMatch :: TextVariant [] -> TextVariantMatch r [] -> r Source # | |
(KnownSymbol lbl, TextVariantMatcher r ts) => TextVariantMatcher r (lbl ': ts) Source # | |
Defined in SuperRecord.Variant.Text 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)
buildTextVariant :: Text -> Maybe (TextVariant opts) Source #
Instances
TextVariantBuilder ([] :: [Symbol]) Source # | |
Defined in SuperRecord.Variant.Text buildTextVariant :: Text -> Maybe (TextVariant []) Source # | |
(KnownSymbol lbl, TextVariantBuilder ts) => TextVariantBuilder (lbl ': ts) Source # | |
Defined in SuperRecord.Variant.Text buildTextVariant :: Text -> Maybe (TextVariant (lbl ': ts)) Source # |