Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype WithOptional f result = WithOptional {
- getOptional :: Maybe (f result)
- withOptional :: forall a b f. Coercible a (f b) => Maybe a -> WithOptional f b
- withOptionalField' :: forall a b f. (Coercible a (f b), HasCodec a) => Text -> ObjectCodec (WithOptional f b) (WithOptional f b)
- withOptionalFieldWith' :: forall a b f. Coercible a (f b) => Text -> ValueCodec a a -> ObjectCodec (WithOptional f b) (WithOptional f b)
Documentation
newtype WithOptional f result Source #
Enrich a Functor
f
with optionality; this is primarily useful when
one wants to annotate fields as optional when using the Higher-Kinded Data
pattern.
WithOptional
f
is equivalent to Compose Maybe f
.
WithOptional | |
|
Instances
withOptional :: forall a b f. Coercible a (f b) => Maybe a -> WithOptional f b Source #
WithOptional
smart constructor for the special case of optional values
that are representationally equivalent to some "wrapper" type.
For example:
withOptional @HeaderTransformsAction headers == WithOptional $ fmap HeadersTransform headers
In other words: this function observes the isomorphism between
and Maybe
a
if an isomorphism exists between WithOptional
f ba
and f b
.
withOptionalField' :: forall a b f. (Coercible a (f b), HasCodec a) => Text -> ObjectCodec (WithOptional f b) (WithOptional f b) Source #
Define a field in an object codec that applies withOptional
when
decoding, and applies getOptional
when encoding.
withOptionalFieldWith' :: forall a b f. Coercible a (f b) => Text -> ValueCodec a a -> ObjectCodec (WithOptional f b) (WithOptional f b) Source #
Define a field in an object codec that applies withOptional
when
decoding, and applies getOptional
when encoding.
This version takes a codec for the underlying value type as an argument.