An example for struct deep merging (with key path deletable). #1313
morlay
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
It could be simpler for the evaluator if you avoid the
package structural
import (
"github.com/hofstadter-io/cuetils/recurse"
)
#upsertF: {
#next: _
#func: {
#X: _
#U: _
upsert: {
for i,x in #X {
let u = #U[i]
// if in upsert, we're going to replace
if u != _|_ {
// if orig is a struct, recurse
if (x & {...}) != _|_ {
"\(i)": (#next & { #X: x, #U: u }).upsert
}
// otherwise set to u
if (x & {...}) == _|_ {
"\(i)": u
}
}
// if not in upsert, copy orig x
if u == _|_ {
"\(i)": x
}
}
// now look for anything in U that is not in X
{
for i,u in #U {
if #X[i] == _|_ {
"\(i)": u
}
}
}
}
}
}
#Upsert: recurse.#RecurseN & { #funcFactory: #upsertF } |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A question:
Could it be simpler ?
Beta Was this translation helpful? Give feedback.
All reactions