Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Couldn't a "possibly null" member access operator help here? E.g.:

   var key = user?.them?.public_keys?.primary?.bundle;
where

    object?.property
is equivalent to

    object ? object.property : null


I'd rather just have a functions similar to clojure/clojurescript's get-in[0], update-in[1], assoc-in[2], dissoc-in[3] for working with nested objects/arrays. These are pretty easy to write in Python, Ruby, and Javascript, although I'm not aware of any public library that implements them. It really makes working with JSON-returning apis a breeze.

[0] - http://clojuredocs.org/clojure_core/clojure.core/get-in

[1] - http://clojuredocs.org/clojure_core/clojure.core/update-in

[2] - http://clojuredocs.org/clojure_core/clojure.core/assoc-in

[3] - http://clojuredocs.org/clojure_core/clojure.core/dissoc-in


The authors JWalk is basically get-in. Lenses, as popularised by Haskell, solve a similar problem.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: