This type of stuff could be done easily w/ the existing sequence fns
You first one is simply
(filter even? (range 10))
The second one is a little trickier, but it could be written like this
(map (juxt identity #(* 2 %))
(filter even?
(range 10)))
This is usually considered better form than using when/if directly.
Now, these are finite examples. If you wanted an infinite lazy seq,
you could substitute (interate inc 1) for (range 10). Just be very
careful evaluating this at a REPL.
Unless I missed the point of your post entirely.
Sean
On Feb 10, 7:23 am, Mark Carter <[email protected]> wrote:
> I know that loo exists - and I'm puzzled by what the lazy functions
> do.
>
> What I think would be interesting functionality is to have an emitter/
> collector combination, for example:
>
> (collect
> (doseq [ n (range 10)]
> (when (even? n) (emit n))))
>
> would return the list (0 2 4 6 8). Any ideas how I could implement
> this?
>
> You might ask why anybody would want this. Well, I think it would be
> neat because it separates your logic from actual looping mechanics.
> I'm saying "I don't care how the list is constructed, just as long as
> it is". I know there are functions like filter that would be better
> in this particular example - but I'm only using it for illustrative
> purposes.
>
> It would also allow you do do something like
>
> (collect
> (doseq [ n (range 10)]
> (when (even? n)
> (emit n)
> (emit (* 2 n)))))
>
> to give you the list (0 0 2 4 4 8 6 12 8 16). Admittedly this
> particular example might not be of much use; but the general idea is
> that it allows you to collect all sorts of weird and wonderful things,
> possibly involving complicated logic as to when/if you want things
> collection.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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