You version does not work for certain kind of data, (as did mine), see
my answer to Meikel for more detail,
--
Laurent
2009/4/23 Christophe Grand christo...@cgrand.net:
Hi all!
(defn mystery-function [pred coll]
(lazy-seq
(when (seq coll)
(let [[run etc] (split-with pred coll)]
On Thu, Apr 23, 2009 at 9:44 AM, Laurent PETIT laurent.pe...@gmail.com wrote:
Hi Meikel,
It seems to me that your version is the only safe one so far, that
would succesfully indefinitely return values with this test:
(dorun (mystery-function true? :foo (repeat true)))
Mine, a new version
*Warning this message contains mutable state and may hurt functional
sensibilities.*
Ugly hack:
(defn my-split-with [pred coll]
(let [s (atom coll)
p #(when-let [r (pred %)] (swap! s rest) r)]
[(take-while p coll) (drop-while pred (lazy-seq @s))]))
Now it works ;-)
Laurent
1:2 user= (reduce #(concat %1 (if ( %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4 2))
(3 4 5 :foo 8 4 2)
Not good, the expected result would have been
(3 4 5 :foo 8 4 2 :foo)
Regards,
--
Laurent
2009/4/23 Emeka emekami...@gmail.com:
(reduce #(concat %1 (if ( %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4
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:
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?
Laurent PETIT a écrit :
2009/4/23 Christophe Grand christo...@cgrand.net:
*Warning this message contains mutable state and may hurt functional
sensibilities.*
Ugly hack:
(defn my-split-with [pred coll]
(let [s (atom coll)
p #(when-let [r (pred %)] (swap! s rest) r)]
Laurent PETIT a écrit :
I guess you're right. But a little warning in the javadoc could help
newcomers not shoot themselves in the foot.
And the problem is, calling directly (second) without calling (first)
would work most of the time. I wanted to make it fail every time =
same behaviour
2009/4/23 Christophe Grand christo...@cgrand.net:
Laurent PETIT a écrit :
I guess you're right. But a little warning in the javadoc could help
newcomers not shoot themselves in the foot.
And the problem is, calling directly (second) without calling (first)
would work most of the time. I
Laurent PETIT a écrit :
2009/4/23 Christophe Grand christo...@cgrand.net:
Laurent PETIT a écrit :
I guess you're right. But a little warning in the javadoc could help
newcomers not shoot themselves in the foot.
And the problem is, calling directly (second) without calling (first)
2009/4/23 Christophe Grand christo...@cgrand.net:
Laurent PETIT a écrit :
2009/4/23 Christophe Grand christo...@cgrand.net:
Laurent PETIT a écrit :
I guess you're right. But a little warning in the javadoc could help
newcomers not shoot themselves in the foot.
And the problem is, calling
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)
On Wed, Apr 22, 2009 at 4:57 PM, samppi rbysam...@gmail.com wrote:
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
On Wed, Apr 22, 2009 at 9:58 AM, Michael Wood esiot...@gmail.com wrote:
On Wed, Apr 22, 2009 at 4:57 PM, samppi rbysam...@gmail.com wrote:
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
2009/4/22 Michael Wood esiot...@gmail.com:
On Wed, Apr 22, 2009 at 4:57 PM, samppi rbysam...@gmail.com wrote:
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
Hi,
Am 22.04.2009 um 16:57 schrieb samppi:
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
On Wed, Apr 22, 2009 at 8:03 PM, Meikel Brandmeyer m...@kotka.de wrote:
Hi,
Am 22.04.2009 um 16:57 schrieb samppi:
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
Hi Micheal,
Am 22.04.2009 um 21:18 schrieb Michael Wood:
Your version gives the same answer as mine, but I believe what he
wants is something that skips over all the elements that pass the test
and only inserts one instance of o after them. That's why in his
example there is not a :foo after
Hi all!
(defn mystery-function [pred coll]
(lazy-seq
(when (seq coll)
(let [[run etc] (split-with pred coll)]
(if (seq run)
(concat run (cons :foo (mystery-function pred etc)))
(cons (first coll) (mystery-function pred (rest coll
Christophe
19 matches
Mail list logo