[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations
From: |
Nicolas Petton |
Subject: |
Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations |
Date: |
Thu, 02 Mar 2017 13:58:19 +0100 |
Michael Heerdegen <address@hidden> writes:
> BTW, with the suggested approach, you can use a counter to specify a
> break condition, like here, were I want to calculate the stream of
> natural numbers up to a place where two subsequent elements have a
> difference that is not less than 2 (which never happens), but where I
> say I want to have at most 25 elements:
>
> #+begin_src emacs-lisp
> (seq-into-sequence
> (car
> (stream-divide
> (let (the-naturals) (setq the-naturals (stream-cons 1 (seq-map #'1+
> the-naturals))))
> (let ((counter 0))
> (lambda (this next)
> (and (< (cl-incf counter) 25)
> (< (- next this) 2)))))))
> ==> (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25)
> #+end_src
That's really neat!
Cheers,
Nico
signature.asc
Description: PGP signature