Thanks once again Marko. The only thing that I am having trouble
understanding is this:
1. What exactly happens when an item is passed to #(keyset-b (key-fn %)) ? Does
keyset-b looks up itself (because collections are functions) for the item
which contains *:id X *and returns true/false?
Let's assume that key-fn is defined as #(.getID %) so we have:
#(keyset-b #(.getID %))
And now let's assume that item-object is passed to it. So, #(.getID %)
returns,
let's say, the number 3 (which is the value of the id). How exactly is that
number is being looked up in keyset-b? How
Thanks a lot Marko :)
On Friday, March 22, 2013 12:44:06 PM UTC+2, Marko Topolnik wrote:
Let's assume that key-fn is defined as #(.getID %) so we have:
#(keyset-b #(.getID %))
And now let's assume that item-object is passed to it. So, #(.getID %)
returns,
let's say, the number 3 (which
Marko,
Can you please do me a favor and break down the function you suggested me?
I understand partially how it works but I am having trouble to fully get it.
Thank you for your time.
On Monday, March 11, 2013 11:05:47 PM UTC+2, Marko Topolnik wrote:
Another approach, preserving the order of
First we build a set of all the keys in *list-b*:
(into #{} (map key-fn list-b))
Let's call that set *keyset-b. *Then we use *keyset-b* as a function which
returns truthy (non-nil) for any key that is contained in it, and compose
it with our *key-fn*:
(comp keyset-b key-fn)
This results in
Thanks a lot Marko. Much better now :)
I also wanted to ask you why did you mention in a previous post that you
prefer using *remove *than *filter + complement*. Is there a reason for
this or just a personal preference?
Ryan
On Thursday, March 21, 2013 5:37:33 PM UTC+2, Marko Topolnik wrote:
Personal preference. It causes less mental load because it more obviously
spells out what you are doing.
On Thursday, March 21, 2013 4:58:08 PM UTC+1, Ryan wrote:
Thanks a lot Marko. Much better now :)
I also wanted to ask you why did you mention in a previous post that you
prefer using
Thanks Marko. I do have couple more q's for you just to ensure I got
everything right:
(comp keyset-b key-fn)
This results in a function that first applies *key-fn*, then *keyset-b*.
So it's like #(keyset-b (key-fn %)). Let's call this function *predicate*.
1. What exactly happens when an
On Thursday, March 21, 2013 5:21:53 PM UTC+1, Ryan wrote:
Thanks Marko. I do have couple more q's for you just to ensure I got
everything right:
(comp keyset-b key-fn)
This results in a function that first applies *key-fn*, then *keyset-b*.
So it's like #(keyset-b (key-fn %)). Let's call
On Mar 11, 2013, at 17:09 , Ryan arekand...@gmail.com wrote:
What if, i had two clojure lists, with hash-maps which have the same keys and
based on a specific key, i wanted to find the items from list-a which do not
exist in list-b. Would i go with the two functions you suggested or is there
Assuming :id is the key you care about:
(filter (comp (complement (set (map :id list-b))) :id)
list-a)
This is almost exactly the same as the one from an earlier post here:
(remove (comp (into #{} (map key-fn list-b)) key-fn) list-a)
I'd prefer *remove* to *filter + complement*,
On Monday, March 11, 2013 11:09:31 PM UTC+1, Ryan wrote:
What if, i had two clojure lists, with hash-maps which have the same keys
and based on a specific key, i wanted to find the items from list-a which
do not exist in list-b. Would i go with the two functions you suggested or
is there
Thanks guys for your replies. I will re-read everything carefully and
decide what to do :)
Ryan
On Tuesday, March 12, 2013 11:14:17 AM UTC+2, Marko Topolnik wrote:
On Monday, March 11, 2013 11:09:31 PM UTC+1, Ryan wrote:
What if, i had two clojure lists, with hash-maps which have the same
On Mar 12, 2013, at 04:11 , Marko Topolnik marko.topol...@gmail.com wrote:
This is almost exactly the same as the one from an earlier post here:
(remove (comp (into #{} (map key-fn list-b)) key-fn) list-a)
I'd prefer remove to filter + complement, though.
Ah, I should have read the rest
Hello,
I have two lists which contain java objects of the same class. I am trying
to find out if there is a clojure function which i can use to compare those
lists based on a key and return the objects from list A that do not exist
in list B.
Is there such a function in clojure? If not, what
Well, java.util.List specifies a retainAll(Collection c) method which is
basically the intersection between the 2 collections (the Collection
this is called on and the argument). You are actually looking for the
'difference' but if you have the intersection and the total it's pretty
trivial to
On 11/03/13 18:35, Jim - FooBar(); wrote:
Well, java.util.List specifies a retainAll(Collection c) method which
is basically the intersection between the 2 collections (the
Collection this is called on and the argument). You are actually
looking for the 'difference' but if you have the
Hey Jim,
Thanks for your replies for starters.
Indeed I do not care what will happen to the original lists, i only care to
find out which objects from list A do not exist in list B. Ignore the key
part.
I was aware of the functionality which is provided by java.util.List but I
was hoping for
There is clojure.data/diff, but whether it would work for you would depend on
whether Clojure's = would compare your Java objects for equality in the way
that you wanted. You could try it out on some test case to see.
http://clojure.github.com/clojure/clojure.data-api.html#clojure.data/diff
Clojure itself is being pragmatic about many many things... If you want
removeAll() then use it...what can be better than a single method call?
mind you though, what Andy said applies here. It depends what you want
to compare for...you want to do a 'deep' comparison (per =) or fall back
to
I have two lists which contain java objects of the same class. I am trying
to find out if there is a clojure function which i can use to compare those
lists based on a key and return the objects from list A that do not exist
in list B.
Lists as in Clojure lists, or as in
Another approach, preserving the order of list-a, would be
(remove (comp (into #{} (map key-fn list-b)) key-fn) list-a)
On Monday, March 11, 2013 10:01:09 PM UTC+1, Marko Topolnik wrote:
I have two lists which contain java objects of the same class. I am trying
to find out if there is a
Thank you all for your replies.
@Marko, well, at first my question was intended to be more generic, but in
reality I am dealing with two java.util.Lists
I probably didn't described very well what I wanted in the first place. All
the objects in those lists contain an id property which has a
On Monday, March 11, 2013 10:55:12 PM UTC+1, Ryan wrote:
Thank you all for your replies.
@Marko, well, at first my question was intended to be more generic, but in
reality I am dealing with two java.util.Lists
I only asked because if they aren't java.util.Lists to begin with, you'd
I only asked because if they aren't java.util.Lists to begin with, you'd
definitely not want to convert into one just to use removeAll.
What if, i had two clojure lists, with hash-maps which have the same keys
and based on a specific key, i wanted to find the items from list-a which
do
On 11/03/13 21:55, Ryan wrote:
I probably didn't described very well what I wanted in the first
place. All the objects in those lists contain an id property which
has a unique value. I am trying to find out, which objects from the
first list, based on that id property, are not included in list
26 matches
Mail list logo