(def test-galaxy [{:quad-col 0, :quad-row 0, :sec-row 4, :sec-col 4, :type
:E}
{:quad-col 0, :quad-row 0, :sec-row 4, :sec-col 3, :type
:base}
{:quad-col 3, :quad-row 5, :sec-row 7, :sec-col 5, :type
:star}
{:quad-col 1, :quad-row 3, :sec-row 0, :sec-col 5, :type
:klingon}])
(defn get-quad-pieces
[galaxy [quad-row quad-col]]
(let [quad-pieces (filter (fn [elem] (and (= (:quad-row elem) quad-row)
(= (:quad-col elem)
quad-col))) galaxy)]
quad-pieces))
(get-quad-pieces test-galaxy [0 0])
; ({:quad-col 0, :quad-row 0, :sec-row 4, :sec-col 4, :type :E} {:quad-col
0, :quad-row 0, :sec-row 4, :sec-col 3, :type :base})
Jay Fields makes an excellent argument for using core functions, instead of
anonyous functions, wherever possible
http://blog.jayfields.com/2012/10/clojure-avoiding-anonymous-functions.html
In his example, he was grouping elements, not filtering by multiple values,
which is what I'm trying to do.
I'm trying to refactor one particular piece of code, and have no idea what,
if any, core functions, would work.
I want to filter a list of hashes, based on some of the values - (code
topside)
I have come up with a few variations of the code, with reduce, etc - but
they all use an anonyous function. The only options I can figure, using
filter or reduce, require a variable to represent each list element, which
means an anon-function with a parameter.
Thanks.
Okay, I now have two questions - why does the code-highlighter insist on
putting the code at the top, instead of in the middle, where I had the
cursor? :)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.