On 13 Dec 2008, at 12:39, Dave Newton wrote:
>
> --- On Sat, 12/13/08, Stephen Parker wrote:
>> On 12 Dec 2008, at 23:10, Mark Fredrickson wrote:
>>> [...] insert 3 before every item less than or equal to 5 in a seq:
>>
>> (def bar [24 6 5 5 7 5 8 2])
>> (insert-before-if #(<= 5 %) 3 bar)
>>
>> => (3 24 3 6 3 5 3 5 3 7 3 5 3 8 2)
>
> Er...
Must have been asleep:
(def bar [24 6 5 5 7 5 8 2])
(defn insert-before-if [pred ins lst]
(mapcat #(if (pred %) [ins %] [%]) lst))
(insert-before-if #(<= % 5) 3 bar)
stephen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---