Re: using take-while with pred function that has state

2012-09-05 Thread shaobohou
On Monday, 3 September 2012 14:03:42 UTC+1, Dave Sann wrote: > > (defn take-while-reduce > "fancy take accumulating a reduced value on taken items > this value can then be tested in the take fn > Much appreciated. -- You received this message because you are subscribed to the Google Grou

Re: using take-while with pred function that has state

2012-09-05 Thread shaobohou
On Monday, 3 September 2012 06:26:07 UTC+1, Stephen Compall wrote: > > (->> ss (map tok-fn), (reductions (partial apply merge) #{}), > (take-while #(...)), (map #(do %2 %1) ss), last) > > Use of `atom' for this sort of thing is certainly an antipattern, so > consider any alternative that su

Re: using take-while with pred function that has state

2012-09-04 Thread Stephen Compall
On Tue, 2012-09-04 at 15:24 -0700, Sean Corfield wrote: > But that is a hypothetical, yes? You're not suggesting that take-while > actually does that, right? Right. As of right now. -- Stephen Compall "^aCollection allSatisfy: [:each | aCondition]": less is better than -- You received this m

Re: using take-while with pred function that has state

2012-09-04 Thread Sean Corfield
On Tue, Sep 4, 2012 at 2:23 PM, Stephen Compall wrote: > On Tue, 2012-09-04 at 09:48 -0700, Sean Corfield wrote: >> Stephen, could you elaborate on this? > > Requiring pred to be free of side effects provides many invariants about > it to the `take-while' implementation; the legality of out-of-ord

Re: using take-while with pred function that has state

2012-09-04 Thread Stephen Compall
On Tue, 2012-09-04 at 09:48 -0700, Sean Corfield wrote: > Stephen, could you elaborate on this? Requiring pred to be free of side effects provides many invariants about it to the `take-while' implementation; the legality of out-of-order calling is just one of them. > My reading of the side-effect

Re: using take-while with pred function that has state

2012-09-04 Thread Sean Corfield
On Mon, Sep 3, 2012 at 1:58 PM, Stephen Compall wrote: > On Sun, 2012-09-02 at 23:02 -0700, Ben Wolfson wrote: >> Can you say what this means (the note about take-while being called in >> coll order)? >> >> Does it mean that it's not a guarantee of the API that the predicate >> passed to take-whil

Re: using take-while with pred function that has state

2012-09-03 Thread Ben Wolfson
On Mon, Sep 3, 2012 at 10:36 PM, Aaron Cohen wrote: > > It wouldn't even be all that insane if you had 1000 otherwise idle > cores sitting around and an expensive enough predicate. Touché (perhaps up to a factor of n). (Though I suspect you need more assumptions given that the specific algorithm

Re: using take-while with pred function that has state

2012-09-03 Thread Aaron Cohen
On Tue, Sep 4, 2012 at 1:24 AM, Ben Wolfson wrote: > On Mon, Sep 3, 2012 at 1:58 PM, Stephen Compall > wrote: > Of course take-while might cause more of a lazy seq to be realized > than is present in its output because of seq chunking. But I'd *hope* > that it wouldn't exacerbate that by reservin

Re: using take-while with pred function that has state

2012-09-03 Thread Ben Wolfson
On Mon, Sep 3, 2012 at 1:58 PM, Stephen Compall wrote: >> I would have hoped that would be guaranteed > > Nevertheless, by declaring "pred must be free of side-effects", > `take-while' is refusing to make that promise, among many others. It seems like a leap to go from pred being free of side-eff

Re: using take-while with pred function that has state

2012-09-03 Thread Stephen Compall
On Mon, 2012-09-03 at 01:12 -0700, Alan Malloy wrote: > (map #(do %2 %1) c1 c2) is a neat trick I hadn't seen in this context; > thanks for showing me! Perhaps you'd also like to advocate for the inclusion of `first-arg', which has several other uses, in core? :) -- Stephen Compall ^aCollection

Re: using take-while with pred function that has state

2012-09-03 Thread Stephen Compall
On Sun, 2012-09-02 at 23:02 -0700, Ben Wolfson wrote: > Can you say what this means (the note about take-while being called in > coll order)? > > Does it mean that it's not a guarantee of the API that the predicate > passed to take-while be called *successively* on the items in the > collection pa

Re: using take-while with pred function that has state

2012-09-03 Thread Dave Sann
I have used the following (from a bunch of utils I have for seqs) in the past to do this kind of thing. You will need to define the reduce-fn and the predicate you need. examples below in the comment. (defn take-while-reduce "fancy take accumulating a reduced value on taken items this va

Re: using take-while with pred function that has state

2012-09-03 Thread Dave Sann
I have used the following in the past in some utils I have for seqs: (defn take-while-reduce "fancy take accumulating a reduced value on taken items this value can then be tested in the take fn e.g (take-while-reduce 0 (fn [v i] (inc v)) (fn [v i] (= v i))

Re: using take-while with pred function that has state

2012-09-03 Thread Alan Malloy
(map #(do %2 %1) c1 c2) is a neat trick I hadn't seen in this context; thanks for showing me! On Sunday, September 2, 2012 10:26:07 PM UTC-7, Stephen Compall wrote: > > On Fri, 2012-08-31 at 05:08 -0700, shaobohou wrote: > > I have written the following function using take-while and a pred > >

Re: using take-while with pred function that has state

2012-09-02 Thread Ben Wolfson
On Sun, Sep 2, 2012 at 10:25 PM, Stephen Compall wrote: > On Fri, 2012-08-31 at 05:08 -0700, shaobohou wrote: >> I have written the following function using take-while and a pred >> function with an atom to store the set of unique tokens. It works > > Only because in the current implementation, ta

Re: using take-while with pred function that has state

2012-09-02 Thread Stephen Compall
On Fri, 2012-08-31 at 05:08 -0700, shaobohou wrote: > I have written the following function using take-while and a pred > function with an atom to store the set of unique tokens. It works Only because in the current implementation, take-while happens to be called in coll order, which is not a guar