This solution, I think, does not do more map first than needed, avoids
computing len and pieces more than once, uses nthnext to avoid extra cost
of drop and computes the example
(first (second (split-at-subsequence [1 2] (range
(defn split-at-subsequence [mark input]
(when-let [sequenc
On Fri, Feb 24, 2012 at 2:43 PM, Alan Malloy wrote:
> Why would you (remove nil? (map f coll))? That's what keep is for:
> (keep f coll).
Why would you (remove nil? (map f coll))? Because you didn't know
about keep, obviously. :)
--
You received this message because you are subscribed to the Go
Why would you (remove nil? (map f coll))? That's what keep is for:
(keep f coll).
On Feb 24, 11:20 am, Cedric Greevey wrote:
> On Fri, Feb 24, 2012 at 2:17 PM, JuanManuel Gimeno Illa
>
> wrote:
> > What I don't understand of your solution is the (map seq (step pieces))
> > because for me it is c
On Fri, Feb 24, 2012 at 2:17 PM, JuanManuel Gimeno Illa
wrote:
> What I don't understand of your solution is the (map seq (step pieces))
> because for me it is clear that each of the sequences generated by step is a
> seq, so why do you need to seq it?
It's the combination of (remove nil? (map se
El viernes 24 de febrero de 2012 18:46:03 UTC+1, Cedric Greevey escribió:
>
> On Fri, Feb 24, 2012 at 11:30 AM, JuanManuel Gimeno Illa wrote:
>
> > I think it would be better to create the lazy-seq over a function that
> uses
> > the pieces in order to not to explode input with partition-all and
On Fri, Feb 24, 2012 at 11:30 AM, JuanManuel Gimeno Illa
wrote:
> Maybe this version is clearer:
>
> (defn split-at-subsequence [mark input]
> (when-let [sequence (seq input)]
> (let [len (count mark)
> pieces (partition-all len 1 sequence)
> [fst rs
One variation making the lazy-sequence only over the pieces:
(defn split-at-subsequence [mark input]
(let [len (count mark)
split-at-subseq (fn split-at-subseq [pieces]
(when (seq pieces)
(let [[fst rst] (sp
Maybe this version is clearer:
(defn split-at-subsequence [mark input]
(when-let [sequence (seq input)]
(let [len (count mark)
pieces (partition-all len 1 sequence)
[fst rst] (split-with #(not= mark %) pieces)
head (map first fst)
One implementation using only one recursive function and the sequence
library:
(defn split-at-subsequence [mark input]
(when-let [sequence (seq input)]
(let [len (count mark)
pieces (partition-all len 1 sequence)
[fst rst] (split-with #(not= mark %)
On Thu, Feb 16, 2012 at 14:06 -0600, Michael Gardner wrote:
> On Feb 16, 2012, at 11:08 AM, Wolodja Wentland wrote:
>
> > Thanks for the explanation. What would be a good way to ensure that the
> > subseqeuence are lazy too?
>
> I can't think of a good way to do this with higher-order functions,
On Feb 16, 2012, at 11:08 AM, Wolodja Wentland wrote:
> Thanks for the explanation. What would be a good way to ensure that the
> subseqeuence are lazy too?
I can't think of a good way to do this with higher-order functions, so you'll
probably have to write a recursive function that "manually" i
On Thu, Feb 16, 2012 at 10:51 -0600, Michael Gardner wrote:
> partition-by is lazy in that it only splits its argument into as many
> subseqs as requested; the subseqs themselves are not lazy. So when you
> partition-by the result of (replace-subseq-with-sentinel [1 2] sentinel
> (range)) and then
partition-by is lazy in that it only splits its argument into as many subseqs
as requested; the subseqs themselves are not lazy. So when you partition-by the
result of (replace-subseq-with-sentinel [1 2] sentinel (range)) and then
request the infinite third subseq thereof, partition-by won't ter
Hi all,
I am trying to implement a function that splits any given sequence on a
subsequence. I would like it to behave like this:
user> (split-at-subsequence [5 6] (range 10))
((0 1 2 3 4) (7 8 9))
user> (split-at-subsequence [5 7] (range 10))
((0 1 2 3 4 5 6 7 8 9))
user> (fi
14 matches
Mail list logo