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
It's very easy in Argo to decode related objects if they are children. I have a situation where I want to link to the parent objects going up the chain.
Say I have an API that returns this hierarchy of objects:
Foo
Bar1
Baz11
Bar2
Baz21
When they are all decoded, i can get to the Baz21 by saying foo.bars[1].bazes[0]. Now, how, having bazes[0] can I refer back to the foo? The initialisation process is somewhat blackboxed in this case since each struct's decode method takes json only for own and child objects. And there is no reference for the parental objects at all.
Has anyone done anything similar to this?
The text was updated successfully, but these errors were encountered:
This particular use case is difficult with Argo while maintaining maximum type safety. We have been successful in the past in this by having our bazes decode function return a decoded function instead of the Baz object that takes the final argument and returns the Baz. For instance:
extensionBaz:Decodable{staticfunc decode(j:JSON)->Decoded<String->Baz>{returncurry(Baz.init)<^> j <|""<*> y <|""}}
Where that final String value needs to come from foo. Then in the Foo decode function, get the string and finish the application with <*>. It's a little weird though and we've been thinking of different methods to tackle this.
It's very easy in Argo to decode related objects if they are children. I have a situation where I want to link to the parent objects going up the chain.
Say I have an API that returns this hierarchy of objects:
When they are all decoded, i can get to the Baz21 by saying
foo.bars[1].bazes[0]
. Now, how, havingbazes[0]
can I refer back to the foo? The initialisation process is somewhat blackboxed in this case since each struct's decode method takes json only for own and child objects. And there is no reference for the parental objects at all.Has anyone done anything similar to this?
The text was updated successfully, but these errors were encountered: