Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.StringVariants.NullableNonEmptyText
Contents
Synopsis
- newtype NullableNonEmptyText (n :: Nat) = NullableNonEmptyText (Maybe (NonEmptyText n))
- mkNonEmptyTextWithTruncate :: forall (n :: Nat). (KnownNat n, 1 <= n) => Text -> Maybe (NonEmptyText n)
- compileNullableNonEmptyText :: Integer -> QuasiQuoter
- type IsNullableNonEmptyText (n :: Nat) (s :: Symbol) = (KnownSymbol s, KnownNat n, SymbolNonEmpty s, SymbolWithNoSpaceAround s, SymbolNoLongerThan s n)
- literalNullableNonEmptyText :: forall (s :: Symbol) (n :: Nat). IsNullableNonEmptyText n s => NullableNonEmptyText n
- mkNullableNonEmptyText :: forall (n :: Nat). (KnownNat n, 1 <= n) => Text -> Maybe (NullableNonEmptyText n)
- parseNullableNonEmptyText :: forall (n :: Nat). (KnownNat n, 1 <= n) => Text -> Object -> Parser (NullableNonEmptyText n)
- nullNonEmptyText :: forall (n :: Nat). NullableNonEmptyText n
- maybeTextToTruncateNullableNonEmptyText :: forall (n :: Nat). (KnownNat n, 1 <= n) => Maybe Text -> NullableNonEmptyText n
- nonEmptyTextToNullable :: forall (n :: Nat). NonEmptyText n -> NullableNonEmptyText n
- maybeNonEmptyTextToNullable :: forall (n :: Nat). Maybe (NonEmptyText n) -> NullableNonEmptyText n
- nullableNonEmptyTextToMaybeText :: forall (n :: Nat). NullableNonEmptyText n -> Maybe Text
- nullableNonEmptyTextToMaybeNonEmptyText :: forall (n :: Nat). NullableNonEmptyText n -> Maybe (NonEmptyText n)
- fromMaybeNullableText :: forall (n :: Nat). Maybe (NullableNonEmptyText n) -> NullableNonEmptyText n
- isNullNonEmptyText :: forall (n :: Nat). NullableNonEmptyText n -> Bool
Documentation
newtype NullableNonEmptyText (n :: Nat) Source #
Newtype wrapper around Maybe NonEmptyText that converts empty string to Nothing
.
is used in API types to represent optional text fields when you do not want an empty string to fail to parse.
Like NullableNonEmptyText
nNonEmptyText
, the payload Text
is guaranteed to be non-empty, within the character limit, and stripped of whitespace.
Unlike NonEmptyText
, it will successfully parse empty strings as nullNonEmptyText
.
Since Aeson version 2.2, fields of this type maybe be missing, null
, or empty without failing to parse.
Avoid using Maybe (NullableNonEmptyText n)
in API types, since it creates unnecessary edge cases that complicate the code.
NB: When using a version of Aeson prior to 2.2, you must use Maybe (NullableNonEmptyText n)
if you want to allow missing or null fields to parse.
data Person = Person { name ::NonEmptyText
50 , catchphrase ::NullableNonEmptyText
500 }
With this type definition, these four JSON objects below are valid and parse as Person Daniel nullNonEmptyText
.
{"name": "Daniel"} {"name": "Daniel", catchphrase: null} {"name": "Daniel", catchphrase: ""} {"name": "Daniel", catchphrase: " "}
These two JSON objects parses as Person Daniel (mkNullableNonEmptyText "Yabba-Dabba Do!")
{"name": "Daniel", catchphrase: "Yabba-Dabba Do!"} {"name": "Daniel", catchphrase: " Yabba-Dabba Do! "}
Use nullableNonEmptyTextToMaybeNonEmptyText
to extract Maybe (NonEmptyText n)
from NullableNonEmptyText n
.
Constructors
NullableNonEmptyText (Maybe (NonEmptyText n)) |
Instances
Constructing
mkNonEmptyTextWithTruncate :: forall (n :: Nat). (KnownNat n, 1 <= n) => Text -> Maybe (NonEmptyText n) Source #
type IsNullableNonEmptyText (n :: Nat) (s :: Symbol) = (KnownSymbol s, KnownNat n, SymbolNonEmpty s, SymbolWithNoSpaceAround s, SymbolNoLongerThan s n) Source #
literalNullableNonEmptyText :: forall (s :: Symbol) (n :: Nat). IsNullableNonEmptyText n s => NullableNonEmptyText n Source #
This requires the text to be non-empty. For the empty text just use the constructor `NullableNonEmptyText Nothing`
mkNullableNonEmptyText :: forall (n :: Nat). (KnownNat n, 1 <= n) => Text -> Maybe (NullableNonEmptyText n) Source #
parseNullableNonEmptyText :: forall (n :: Nat). (KnownNat n, 1 <= n) => Text -> Object -> Parser (NullableNonEmptyText n) Source #
nullNonEmptyText :: forall (n :: Nat). NullableNonEmptyText n Source #
Conversion
maybeTextToTruncateNullableNonEmptyText :: forall (n :: Nat). (KnownNat n, 1 <= n) => Maybe Text -> NullableNonEmptyText n Source #
nonEmptyTextToNullable :: forall (n :: Nat). NonEmptyText n -> NullableNonEmptyText n Source #
maybeNonEmptyTextToNullable :: forall (n :: Nat). Maybe (NonEmptyText n) -> NullableNonEmptyText n Source #
nullableNonEmptyTextToMaybeText :: forall (n :: Nat). NullableNonEmptyText n -> Maybe Text Source #
nullableNonEmptyTextToMaybeNonEmptyText :: forall (n :: Nat). NullableNonEmptyText n -> Maybe (NonEmptyText n) Source #
fromMaybeNullableText :: forall (n :: Nat). Maybe (NullableNonEmptyText n) -> NullableNonEmptyText n Source #
Functions
isNullNonEmptyText :: forall (n :: Nat). NullableNonEmptyText n -> Bool Source #