You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That fails.
So far I solved this with a rather poor solution, another combining operator:
traitEskoLensesextendsScalarLenseswithOptionLenseswithSeqLenseswithOperationswithJsonPathIntegrationwithExtraImplicits {
defwriteIfAbscentCombine[M[_], M2[_], R[_]](outer: Lens[M], inner: Lens[M2])(implicitev: Join[M2, M, R]):Lens[R] =newLensImpl[R]()(ev.get(inner.ops, outer.ops)) {
defretr:JsValue=>Validated[R[JsValue]] = parent =>for {
outerV <- outer.retr(parent)
innerV <- ops.allRight(outer.ops.flatMap(outerV)(x => inner.ops.toSeq(inner.retr(x))))
} yield innerV
defupdated(f: SafeJsValue=>SafeJsValue)(parent: JsValue):SafeJsValue=
outer.updated {
casel: Left[_, _] =>
inner.updated(f)(JsObject())
case r @Right(js) =>
inner.updated(f)(js)
}(parent)
}
}
objectEskoLensesextendsEskoLenses {
implicitclassWriteIfAbscenCombinator(outer: ScalarLens) {
/** * When using this operator, the resulting lens join will not fail when trying to to do inner level writes, it will instead initialize an empty object * * @paraminner * @return*/def/?(inner: ScalarLens):ScalarLens= {
EskoLenses.writeIfAbscentCombine(outer, inner)
}
}
}
I'm sure better solutions could be thought of.
E.g. a combining lens could be a class which can be matched against and from which the inner and outer can be recovered. That way the need for parent node creation could be detected and executed before attempting to write the nested json.
The text was updated successfully, but these errors were encountered:
When trying to write a nested js:
using a single lens
That fails.
So far I solved this with a rather poor solution, another combining operator:
I'm sure better solutions could be thought of.
E.g. a combining lens could be a class which can be matched against and from which the inner and outer can be recovered. That way the need for parent node creation could be detected and executed before attempting to write the nested json.
The text was updated successfully, but these errors were encountered: