Consider using for, and returning the new set of values
(for [[a b] (partition 2 1 coll)]
(if (= (:foo a) (:foo b))
(dissoc a :foo)
a))
Here I use partition so that each item can be compared to the one that
follows it. You would likely want a final step that tacks on the last item
in the input coll (since it is not processed by this code).
On Wednesday, March 4, 2015 at 11:36:34 AM UTC-8, mlimotte wrote:
>
> Probably a reduce is more appropriate.
>
> (reduce
> (fn [x a]
> (your-compare-expression x a) ; the result of this expr is the result
> of the fn and will be 'x' for the next iteration
> )
> 0 b)
>
>
> BTW, a let to bind an atom outside your do-seq, while _not recommended_,
> should work. We would have to see your code to know why it didn't for
> you. Show you code if you're curious, but please don't actually do it this
> way.
>
>
>
> On Tue, Mar 3, 2015 at 10:26 PM, noobcoder <[email protected] <javascript:>
> > wrote:
>
>> Hi,
>> I have the following code structure
>>
>> (do-seq [a b]
>> .
>> .
>> .
>> )
>>
>> For each a in b, I want to check a particular value in a, store it and
>> compare it with the same value in next a. If it is same I want to clear it
>> before next a. I tried to define an x (atom 0) by having a let outside of
>> the do-seq. I can successfully compare the value of the atom and reset it,
>> but when I get the second a the atom value is again 0. How do I go about
>> this?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> <javascript:>
>> 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] <javascript:>
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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.