string-variants-0.3.1.1: Constrained text newtypes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.StringVariants.NullableNonEmptyText

Synopsis

Documentation

newtype NullableNonEmptyText n Source #

Newtype wrapper around Maybe NonEmptyText that converts empty string to Nothing.

NullableNonEmptyText n is used in API types to represent optional text fields when you do not want an empty string to fail to parse. Like NonEmptyText, 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.

Instances

Instances details
Lift (NullableNonEmptyText n :: Type) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Methods

lift :: Quote m => NullableNonEmptyText n -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => NullableNonEmptyText n -> Code m (NullableNonEmptyText n) #

(KnownNat n, 1 <= n) => FromJSON (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

ToJSON (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

KnownNat n => Data (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NullableNonEmptyText n -> c (NullableNonEmptyText n) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NullableNonEmptyText n) #

toConstr :: NullableNonEmptyText n -> Constr #

dataTypeOf :: NullableNonEmptyText n -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NullableNonEmptyText n)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NullableNonEmptyText n)) #

gmapT :: (forall b. Data b => b -> b) -> NullableNonEmptyText n -> NullableNonEmptyText n #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NullableNonEmptyText n -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NullableNonEmptyText n -> r #

gmapQ :: (forall d. Data d => d -> u) -> NullableNonEmptyText n -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> NullableNonEmptyText n -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> NullableNonEmptyText n -> m (NullableNonEmptyText n) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NullableNonEmptyText n -> m (NullableNonEmptyText n) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NullableNonEmptyText n -> m (NullableNonEmptyText n) #

Generic (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Associated Types

type Rep (NullableNonEmptyText n) :: Type -> Type #

Read (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Show (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

NFData (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Methods

rnf :: NullableNonEmptyText n -> () #

Eq (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Ord (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

Hashable (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

type Rep (NullableNonEmptyText n) Source # 
Instance details

Defined in Data.StringVariants.NullableNonEmptyText

type Rep (NullableNonEmptyText n) = D1 ('MetaData "NullableNonEmptyText" "Data.StringVariants.NullableNonEmptyText" "string-variants-0.3.1.1-KjbUPF6eB5P27Tc6XbzPLu" 'True) (C1 ('MetaCons "NullableNonEmptyText" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (NonEmptyText n)))))

Constructing

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`

Conversion

Functions