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
322
322
⇒ Row.Lacks p r
323
323
⇒ Proxy p
324
324
→ (Maybe a → b )
325
- → (b → a )
325
+ → (b → Maybe a )
326
326
→ JsonCodec a
327
327
→ JPropCodec (Record r )
328
328
→ JPropCodec (Record r' )
@@ -350,7 +350,9 @@ recordPropOptionalWith p normalize denormalize codecA codecR = Codec.codec dec'
350
350
b ∷ b
351
351
b = Record .get p val
352
352
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
354
356
355
357
unsafeForget ∷ Record r' → Record r
356
358
unsafeForget = unsafeCoerce
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ newtype Optional a = Optional (CA.JsonCodec a)
54
54
-- | property is not present in the JSON object.
55
55
newtype OptionalWith a b = OptionalWith
56
56
{ normalize ∷ Maybe a → b
57
- , denormalize ∷ b → a
57
+ , denormalize ∷ b → Maybe a
58
58
, codec ∷ CA.JsonCodec a
59
59
}
60
60
@@ -63,7 +63,7 @@ optional ∷ ∀ a. CA.JsonCodec a → Optional a
63
63
optional = Optional
64
64
65
65
-- | 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
67
67
optionalWith normalize denormalize codec = OptionalWith { normalize, denormalize, codec }
68
68
69
69
-- | The class used to enable the building of `Record` codecs by providing a
@@ -103,7 +103,7 @@ else instance rowListCodecConsOptionalWith ∷
103
103
CA .recordPropOptionalWith (Proxy ∷ Proxy sym ) ret.normalize ret.denormalize ret.codec tail
104
104
105
105
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 }
107
107
ret = coerce (Rec .get (Proxy ∷ Proxy sym ) codecs ∷ OptionalWith a b )
108
108
109
109
tail ∷ CA.JPropCodec (Record ro' )
You can’t perform that action at this time.
0 commit comments