Oh cool!  I hadn't thought about this aspect of laziness before.  I can 
see there is some zen here that is worth exploring...

Thanks Mark and Stuart.

-Jeff

Mark Fredrickson wrote:
> Filter is lazy:
>
> http://clojure.org/api#toc228
>
> So you can implement find-first as (first (filter pred coll))
>
> -M
>
> On Feb 10, 2009, at 10:19 AM, Jeff Rose wrote:
>
>   
>> Well, in case someone else needs the same function and it isn't built-
>> in, here's what I'm using in the meantime.  (Based off of the some
>> function that comes in core...)
>>
>> (defn find-first [pred coll]
>>  (when (seq coll)
>>    (if (pred (first coll))
>>      (first coll)
>>      (recur pred (rest coll)))))
>>
>> Cheers,
>> Jeff
>>
>> On Feb 10, 5:18 pm, Jeff Rose <ros...@gmail.com> wrote:
>>     
>>> Hi,
>>>   Is there a built-in function that will return thefirstitemin a
>>> collection that matches a predicate?  (Something equivalent to Ruby's
>>> Enumerable#find...)  Seems pretty basic, but I can'tfindit in the  
>>> docs.
>>>
>>> Thanks,
>>> Jeff
>>>
>>>       
>
> - Mark Fredrickson
> mark.m.fredrick...@gmail.com
> http://www.markmfredrickson.com
>
>
>
>
>
>
>
> >
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to