Re: Sequence puzzle

2009-12-24 Thread samppi
That's great too; I think I'll use this instead, since it doesn't involve unpacking lists. Thanks a lot, both of you. On Dec 24, 11:39 am, Sean Devlin wrote: > We could define a fn called take-until > > (defn take-until >   [pred coll] >   (take-while (complement pred) coll)) > > And get the last

Re: Sequence puzzle

2009-12-24 Thread Sean Devlin
We could define a fn called take-until (defn take-until [pred coll] (take-while (complement pred) coll)) And get the last entry of that user=>(last (take-until odd? [2 4 6 8 9 10 11])) 8 It's based on take-while, so it's lazy. Sean On Dec 24, 1:34 pm, Chouser wrote: > On Thu, Dec 24, 200

Re: Sequence puzzle

2009-12-24 Thread samppi
Excellent, thank you very much! On Dec 24, 11:34 am, Chouser wrote: > On Thu, Dec 24, 2009 at 1:24 PM, samppi wrote: > > I'm having trouble with figuring out something. First, to get the > > first element of a sequence so that (pred element) is false, you do > > (first (drop-while pred sequence)

Re: Sequence puzzle

2009-12-24 Thread Chouser
On Thu, Dec 24, 2009 at 1:24 PM, samppi wrote: > I'm having trouble with figuring out something. First, to get the > first element of a sequence so that (pred element) is false, you do > (first (drop-while pred sequence)). This is lazy, and stops > immediately when the element is found. > > Now, I

Sequence puzzle

2009-12-24 Thread samppi
I'm having trouble with figuring out something. First, to get the first element of a sequence so that (pred element) is false, you do (first (drop-while pred sequence)). This is lazy, and stops immediately when the element is found. Now, I want to get the element *right before* the element returne