every-nth [n coll]
(letfn [(evn [cn s]
(when s
(if (= cn 1)
(lazy-seq (cons (first s) (evn n (next s
(evn (dec cn) (next s)]
(evn n coll)))
Since you want to learn how lazy-seq works here some feedback.
* Make
Hi,
On 25 Nov., 09:40, Sunil S Nandihalli sunil.nandiha...@gmail.com
wrote:
Thanks Meikel for such an insightful feedback. Its hard to imagine so much
thought goes into writing trivial looking functions.
There are several interpretations of the word trivial. One is easy
or simple (where one
Hello everybody,
I just needed a function for every-nth element in a sequence.. I know it
can be trivially implemented as ..
(defn every-nth [n coll]
(letfn [(evn [cn s]
(when s
(if (= cn 1)
(lazy-seq (cons (first s) (evn n (next s
I just needed a function for every-nth element in a sequence.. I know it
can be trivially implemented as ..
(defn every-nth [n coll]
(letfn [(evn [cn s]
(when s
(if (= cn 1)
(lazy-seq (cons (first s) (evn n (next s
(evn (dec
On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose b.gh...@gmail.com wrote:
I just needed a function for every-nth element in a sequence.. I know it
can be trivially implemented as ..
(defn every-nth [n coll]
(letfn [(evn [cn s]
(when s
(if (= cn 1
On Nov 24, 2010, at 11:45 PM, Ken Wesson wrote:
On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose b.gh...@gmail.com
wrote:
I just needed a function for every-nth element in a sequence.. I know it
can be trivially implemented as ..
(defn every-nth [n coll]
(letfn [(evn [cn s
On Wed, Nov 24, 2010 at 11:53 PM, David Sletten da...@bosatsu.net wrote:
On Nov 24, 2010, at 11:45 PM, Ken Wesson wrote:
On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose b.gh...@gmail.com
wrote:
I just needed a function for every-nth element in a sequence.. I know it
can be trivially
for every-nth element in a sequence.. I know it
can be trivially implemented as ..
(defn every-nth [n coll]
(letfn [(evn [cn s]
(when s
(if (= cn 1)
(lazy-seq (cons (first s) (evn n (next s
(evn (dec cn) (next s)]
(evn n coll
Eh. This is weird. It seems that (partition n coll) drops the last
part of coll if it's not a multiple of n in size; e.g. (partition 3 [1
2 3 4 5]) yields ((1 2 3)) and not ((1 2 3) (4 5)). (partition n n []
coll) does do that though.
OTOH,
(mapcat identity (partition 1 n coll))
(apply concat
Thanks everybody,
Clojure community is awesome .. and also I just wanted to learn to use
lazy-seq that is why it was written in the way I showed you all.
Thanks again.
Sunil.
On Thu, Nov 25, 2010 at 11:26 AM, Ken Wesson kwess...@gmail.com wrote:
Eh. This is weird. It seems that (partition n
On 25 November 2010 16:56, Ken Wesson kwess...@gmail.com wrote:
Eh. This is weird. It seems that (partition n coll) drops the last
part of coll if it's not a multiple of n in size; e.g. (partition 3 [1
2 3 4 5]) yields ((1 2 3)) and not ((1 2 3) (4 5)). (partition n n []
coll) does do that
Hi,
On 25 Nov., 05:06, Sunil S Nandihalli sunil.nandiha...@gmail.com
wrote:
(defn every-nth [n coll]
(letfn [(evn [cn s]
(when s
(if (= cn 1)
(lazy-seq (cons (first s) (evn n (next s
(evn (dec cn) (next s)]
(evn n
12 matches
Mail list logo