File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -322,7 +322,7 @@ recordPropOptionalWith
322322 ⇒ Row.Lacks p r
323323 ⇒ Proxy p
324324 → (Maybe a → b )
325- → (b → a )
325+ → (b → Maybe a )
326326 → JsonCodec a
327327 → JPropCodec (Record r )
328328 → JPropCodec (Record r' )
@@ -350,7 +350,9 @@ recordPropOptionalWith p normalize denormalize codecA codecR = Codec.codec dec'
350350 b ∷ b
351351 b = Record .get p val
352352
353- Tuple key (Codec .encode codecA $ denormalize b) : w
353+ case denormalize b of
354+ Just a → Tuple key (Codec .encode codecA a) : w
355+ Nothing → w
354356
355357 unsafeForget ∷ Record r' → Record r
356358 unsafeForget = unsafeCoerce
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ newtype Optional a = Optional (CA.JsonCodec a)
5454-- | property is not present in the JSON object.
5555newtype OptionalWith a b = OptionalWith
5656 { normalize ∷ Maybe a → b
57- , denormalize ∷ b → a
57+ , denormalize ∷ b → Maybe a
5858 , codec ∷ CA.JsonCodec a
5959 }
6060
@@ -63,7 +63,7 @@ optional ∷ ∀ a. CA.JsonCodec a → Optional a
6363optional = Optional
6464
6565-- | A lowercase alias for `OptionalWith`, provided for stylistic reasons only.
66- optionalWith ∷ ∀ a b . (Maybe a → b ) → (b → a ) → CA.JsonCodec a → OptionalWith a b
66+ optionalWith ∷ ∀ a b . (Maybe a → b ) → (b → Maybe a ) → CA.JsonCodec a → OptionalWith a b
6767optionalWith normalize denormalize codec = OptionalWith { normalize, denormalize, codec }
6868
6969-- | The class used to enable the building of `Record` codecs by providing a
@@ -103,7 +103,7 @@ else instance rowListCodecConsOptionalWith ∷
103103 CA .recordPropOptionalWith (Proxy ∷ Proxy sym ) ret.normalize ret.denormalize ret.codec tail
104104
105105 where
106- ret ∷ { normalize ∷ Maybe a → b , denormalize ∷ b → a , codec ∷ CA.JsonCodec a }
106+ ret ∷ { normalize ∷ Maybe a → b , denormalize ∷ b → Maybe a , codec ∷ CA.JsonCodec a }
107107 ret = coerce (Rec .get (Proxy ∷ Proxy sym ) codecs ∷ OptionalWith a b )
108108
109109 tail ∷ CA.JPropCodec (Record ro' )
You can’t perform that action at this time.
0 commit comments