5 ms·
I just don't see how JWalk.getString(user, "them", "public_keys", "primary", "bundle"); is better than user.them.public_keys.primary.bundle What am I mi
by Zelphyr 13y ago
I just don't see how
JWalk.getString(user, "them", "public_keys", "primary", "bundle");
is better than
user.them.public_keys.primary.bundle
What am I missing?
- EvilTrout 13y agoWhat if them is `undefined`? You'll get an exception when usually you just want `undefined` as the answer. As a side note, Ember.js has a nice method for this built in, that works on plain old Javascript objects as well as the heavier Ember ones: Em.get(obj, 'user.them.public_keys.primary.bundle')
- gcb0 13y agotry{} ?
- timbray 13y agoIn Ruby or Python or JS, you should be able to do the user.them... form. In a statically typed language like Java or Go it’s harder, and I happened to be working on an Android app, thus Java.
- currywurst 13y agoNot blowing up when one part of the chain goes "undefined"
- tel 13y agoFailure semantics are the obvious ones. At the very least you'll need some flavor of try { user.them.public_keys.primary.bundle } rescue { OhDamn } Less obvious is the potential for multiple targets. JWalk probably doesn't do this, but it could. For more ideas for how this could work take a look at http://research.microsoft.com/pubs/77415/theessenceofdataaccessincw(ecoop2005).pdf http://research.microsoft.com/pubs/77415/theessenceofdataacc...
- vinkelhake 13y agoThat JWalk library is in Java so there won't be something you can use dynamically like that.
- Zelphyr 13y agoAH! That's the missing piece for me. I thought this was all in JS.
- jayd16 13y agoYou can use GSON and just parse your objects into POJOs and access them with dot notation. In fact, now that I think about it, I wonder if you can rig up your POJOs as Java 8 Option<> and remove some of the null checking. I'll have to look into that.
- tel 13y agoThat's a good place to start. Basing it on the list monad instead of the option monad gives you traversals with monoidal summaries.