File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ import Foreign.Object.ST as FOST
3939import Prim.Row as Row
4040import Record as Record
4141import Type.Proxy (Proxy (..))
42+ import Unsafe.Coerce (unsafeCoerce )
4243
4344-- | A helper for defining JSON codecs for "enum" sum types, where every
4445-- | constructor is nullary, and the type will be encoded as a string.
@@ -217,7 +218,7 @@ instance gCasesSum ∷
217218 let
218219 codecs1 = Record .get (Proxy @name) r ∷ codecs1
219220 r1 = Record .insert (Proxy @name) codecs1 {} ∷ Record r1
220- r2 = Record .delete (Proxy @name) r ∷ Record r2
221+ r2 = unsafeDelete (Proxy @name) r ∷ Record r2
221222 in
222223 case _ of
223224 Inl lhs → gCasesEncode encoding r1 lhs
@@ -391,3 +392,8 @@ encodeSumCase encoding tag jsons =
391392 in
392393 encode jobject $ Obj .fromFoldable $ catMaybes
393394 [ tagEntry, valEntry ]
395+
396+ -- | Same as `Record.delete` deleting only happens at the type level
397+ -- | and the value is left untouched.
398+ unsafeDelete ∷ ∀ r1 r2 l a . IsSymbol l ⇒ Row.Lacks l r1 ⇒ Row.Cons l a r1 r2 ⇒ Proxy l → Record r2 → Record r1
399+ unsafeDelete _ r = unsafeCoerce r
You can’t perform that action at this time.
0 commit comments