javascript - What is clojure.core equivalent of lodash _.pluck -


lodash _.pluck this

var users = [   { 'user': 'barney', 'age': 36 },   { 'user': 'fred',   'age': 40 } ];  _.pluck(users, 'user'); // → ['barney', 'fred'] 

good thing can go deep this:

var users = [   { 'user': {name: 'barney'}, 'age': 36 },   { 'user': {name: 'fred'},   'age': 40 } ];  _.pluck(users, 'user.name'); // ["barney", "fred"] 

is there equivalent in clojure core of this? mean, can create 1 line this

(defn pluck   [collection path]   (map #(get-in % path) collection)) 

and use this:

(def my-coll [{:a {:z 1}} {:a {:z 2}}]) (pluck my-coll [:a :z]) => (1 2) 

i wondering if there's such thing included in clojure , overlooked it.

there no built-in function this. can refer clojure.core api reference , the cheatsheet what's available.

i clojure's syntax light enough feels sufficient use combination of map , accessor utility get-in.

this demonstrates well-adopted principle in clojure community: provide simple defaults , let users compose them need. people argue pluck conflates iteration , querying.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -