On Thu, Apr 23, 2009 at 2:11 PM, Emeka <emekami...@gmail.com> wrote:
> Laurent,
>
> Sampi question was;
>
> > Let's say I have a sequence of integers:
> >  (def a (3 9 1 5 102 -322 ...))
> >
> > Is there a function for inserting an object—let's say :foo—after
> > elements that fulfill a certain predicate?
> > Furthermore, I mean inserting :foo after any block of elements that
> > fulfill it:
> >
> >  (mystery-function (partial > 6) a) ; -> (3 :foo 9 1 5 :foo 102
> > -322 :foo ...)
>
> I didn't know that :foo should also be the last element of the list. Did he
> actually asked for this?

(partial > 6) is the same as #(> 6 %) so Samppi's example puts :foo
after a group of elements if (> 6 element) for each of those elements.

i.e. (1 2 3 4 5 6 7 8) => (1 2 3 4 5 :foo 6 7 8)

because 6 is greater than all of 1, 2, 3, 4, and 5, but none of the
other elements.

and

(3 4 5 8 4 2) => (3 4 5 :foo 8 4 2 :foo)

because 6 is greater than 3, 4 and 5 and it is also greater than 4 and 2.

-- 
Michael Wood <esiot...@gmail.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