def ins

bend-toon-codec@0.1.0.0 · src/expand.bend:108

import bend-toon-codec@0.1.0.0/src/expand.bend as Expand
import Base
import bend-toon-codec@0.1.0.0/src/json.bend as J
import bend-toon-codec@0.1.0.0/src/head.bend as Hd

108# Insert `leaf` at `segs` inside `e`: an object value, a field chain, or
109# whatever sits at the path (then it conflicts unless the path has ended).
110def ins(+e: J.Json, +segs: List<&2, String>, +leaf: J.Json, +strict: Bool) -> Result<&2, &2, String, J.Json>:
111  match e segs:
112    case J.JObj{efs} Nil{}:
113      same.pick(empty_obj(leaf), strict, e, leaf)
114    case J.JObj{efs} Con{s, rest}:
115      wrap.obj(ins(efs, segs, leaf, strict))
116    case J.JField{k, ev, t} Con{s, rest}:
117      cell(Hd.keq(k, s), k, ev, t, ins(ev, rest, leaf, strict), ins(t, segs, leaf, strict))
118    case J.JNil{} Con{s, rest}:
119      Done{J.JField{s, build(rest, leaf), J.JNil{}}}
120    case J.JField{k, ev, t} Nil{}:
121      Done{e}
122    case J.JNil{} Nil{}:
123      Done{e}
124    case _ _:
125      conflict(strict, segs, leaf)

Uses (12)

Used by (1)