Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data NonEmptyText (n :: Nat)
- mkNonEmptyText :: forall n. KnownNat n => Text -> Maybe (NonEmptyText n)
- unsafeMkNonEmptyText :: forall n. KnownNat n => Text -> NonEmptyText n
- mkNonEmptyTextWithTruncate :: forall n. KnownNat n => Text -> Maybe (NonEmptyText n)
- compileNonEmptyText :: Integer -> QuasiQuoter
- compileNonEmptyTextKnownLength :: QuasiQuoter
- nonEmptyTextToText :: NonEmptyText n -> Text
- convertEmptyTextToNothing :: Text -> Maybe Text
- maybeTextToTruncateNullableNonEmptyText :: forall n. KnownNat n => Maybe Text -> NullableNonEmptyText n
- type (<=) (x :: k) (y :: k) = (x <=? y) ~ 'True
- widen :: (1 <= n, n <= m) => NonEmptyText n -> NonEmptyText m
- takeNonEmptyText :: forall m n. (KnownNat m, KnownNat n, n <= m) => NonEmptyText m -> NonEmptyText n
- takeNonEmptyTextEnd :: forall m n. (KnownNat m, KnownNat n, n <= m) => NonEmptyText m -> NonEmptyText n
- chunksOfNonEmptyText :: forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize) => NonEmptyText totalSize -> [NonEmptyText chunkSize]
- filterNonEmptyText :: (Char -> Bool) -> NonEmptyText n -> NonEmptyText n
- (<>|) :: NonEmptyText n -> NonEmptyText m -> NonEmptyText (n + m)
- data ContainsNonWhitespaceCharacters = ContainsNonWhitespaceCharacters
- exactLengthRefinedToRange :: Refined (ContainsNonWhitespaceCharacters && SizeEqualTo n) Text -> NonEmptyText n
- nonEmptyTextFromRefined :: Refined (ContainsNonWhitespaceCharacters && (SizeLessThan n || SizeEqualTo n)) Text -> NonEmptyText n
- refinedFromNonEmptyText :: NonEmptyText n -> Refined (ContainsNonWhitespaceCharacters && (SizeLessThan n || SizeEqualTo n)) Text
- data Prose
- mkProse :: Text -> Maybe Prose
- compileProse :: QuasiQuoter
- proseToText :: Prose -> Text
- newtype NullableNonEmptyText n = NullableNonEmptyText (Maybe (NonEmptyText n))
- mkNullableNonEmptyText :: forall n. KnownNat n => Text -> Maybe (NullableNonEmptyText n)
- nullNonEmptyText :: NullableNonEmptyText n
- compileNullableNonEmptyText :: Integer -> QuasiQuoter
- nonEmptyTextToNullable :: NonEmptyText n -> NullableNonEmptyText n
- maybeNonEmptyTextToNullable :: Maybe (NonEmptyText n) -> NullableNonEmptyText n
- nullableNonEmptyTextToMaybeText :: NullableNonEmptyText n -> Maybe Text
- nullableNonEmptyTextToMaybeNonEmptyText :: NullableNonEmptyText n -> Maybe (NonEmptyText n)
- parseNullableNonEmptyText :: KnownNat n => Text -> Object -> Parser (NullableNonEmptyText n)
- fromMaybeNullableText :: Maybe (NullableNonEmptyText n) -> NullableNonEmptyText n
- isNullNonEmptyText :: NullableNonEmptyText n -> Bool
- useNat :: Integer -> (forall n proxy. KnownNat n => proxy n -> x) -> x
- natOfLength :: proxy (n :: Nat) -> f (other n) -> f (other n)
Non empty text
data NonEmptyText (n :: Nat) Source #
Non Empty Text, requires the input is between 1 and n
chars and not just whitespace.
Instances
Constructing
mkNonEmptyText :: forall n. KnownNat n => Text -> Maybe (NonEmptyText n) Source #
unsafeMkNonEmptyText :: forall n. KnownNat n => Text -> NonEmptyText n Source #
Make a NonEmptyText when you can manually verify the length
mkNonEmptyTextWithTruncate :: forall n. KnownNat n => Text -> Maybe (NonEmptyText n) Source #
Converting
nonEmptyTextToText :: NonEmptyText n -> Text Source #
maybeTextToTruncateNullableNonEmptyText :: forall n. KnownNat n => Maybe Text -> NullableNonEmptyText n Source #
type (<=) (x :: k) (y :: k) = (x <=? y) ~ 'True infix 4 #
Comparison (<=) of comparable types, as a constraint.
Since: base-4.16.0.0
widen :: (1 <= n, n <= m) => NonEmptyText n -> NonEmptyText m Source #
Converts a NonEmptyText
to a wider NonEmptyText
Operations
takeNonEmptyText :: forall m n. (KnownNat m, KnownNat n, n <= m) => NonEmptyText m -> NonEmptyText n Source #
Narrows the maximum length, dropping any remaining trailing characters.
takeNonEmptyTextEnd :: forall m n. (KnownNat m, KnownNat n, n <= m) => NonEmptyText m -> NonEmptyText n Source #
Narrows the maximum length, dropping any prefix remaining characters.
chunksOfNonEmptyText :: forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize) => NonEmptyText totalSize -> [NonEmptyText chunkSize] Source #
O(n) Splits a NonEmptyText
into components of length chunkSize
. The
last element may be shorter than the other chunks, depending on the length
of the input.
filterNonEmptyText :: (Char -> Bool) -> NonEmptyText n -> NonEmptyText n Source #
Identical to the normal text filter function, but maintains the type-level invariant that the text length is <= n, unlike unwrapping the text, filtering, then rewrapping the text.
(<>|) :: NonEmptyText n -> NonEmptyText m -> NonEmptyText (n + m) Source #
Concat two NonEmptyText values, with the new maximum length being the sum of the two maximum lengths of the inputs.
Mnemonic: <>
for monoid, |
from NonEmpty's :|
operator
Conversions between Refined
and NonEmptyText
.
data ContainsNonWhitespaceCharacters Source #
Instances
exactLengthRefinedToRange :: Refined (ContainsNonWhitespaceCharacters && SizeEqualTo n) Text -> NonEmptyText n Source #
nonEmptyTextFromRefined :: Refined (ContainsNonWhitespaceCharacters && (SizeLessThan n || SizeEqualTo n)) Text -> NonEmptyText n Source #
refinedFromNonEmptyText :: NonEmptyText n -> Refined (ContainsNonWhitespaceCharacters && (SizeLessThan n || SizeEqualTo n)) Text Source #
Non-empty, whitespace-trimmed text with no character limit
Whitespace-trimmed, non-empty text, for use with API endpoints.
The rationale is that there are many situations where if a client sends
text that is empty or all whitespace, there's probably a client error.
Not suitable for database fields, as there is no character limit (see
ProsePersistFieldMsg
).
Instances
FromJSON Prose Source # | |
ToJSON Prose Source # | |
Defined in Data.StringVariants.Prose.Internal | |
ToJSONKey Prose Source # | |
Defined in Data.StringVariants.Prose.Internal | |
Semigroup Prose Source # | |
Show Prose Source # | |
Eq Prose Source # | |
Ord Prose Source # | |
ConvertibleStrings Prose Text Source # | |
Defined in Data.StringVariants.Prose.Internal convertString :: Prose -> Text # | |
ConvertibleStrings Prose Text Source # | |
Defined in Data.StringVariants.Prose.Internal convertString :: Prose -> Text # | |
Lift Prose Source # | |
proseToText :: Prose -> Text Source #
Nullable non empty text
newtype NullableNonEmptyText n Source #
Newtype wrapper around Maybe NonEmptyText that converts empty string to Nothing
.
This is aimed primarily at JSON parsing: make it possible to parse empty
string and turn it into Nothing
, in order to convert everything into
Maybe NonEmptyText
at the edge of the system.
While using this for JSON parsing, use Maybe NullableNonEmptyText
. Aeson
special-cases Maybe
to allow nulls, so Maybe
catches the nulls and
NullableNonEmptyText
catches the empty strings.
To extract Maybe NonEmptyText
values from Maybe NullableNonEmptyText
,
use nullableNonEmptyTextToMaybeNonEmptyText
.
Instances
mkNullableNonEmptyText :: forall n. KnownNat n => Text -> Maybe (NullableNonEmptyText n) Source #
Converting
nullableNonEmptyTextToMaybeNonEmptyText :: NullableNonEmptyText n -> Maybe (NonEmptyText n) Source #
parseNullableNonEmptyText :: KnownNat n => Text -> Object -> Parser (NullableNonEmptyText n) Source #
Information
Convenience util if you need a NonEmptyText of a dynamically determined lengths
natOfLength :: proxy (n :: Nat) -> f (other n) -> f (other n) Source #