emacs-devel
[Top][All Lists]
Advanced

[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: Michael Heerdegen
Subject: Re: [PATCH] Gnu Elpa: stream.el: Add some more basic stream operations
Date: Thu, 02 Mar 2017 06:00:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Michael Heerdegen <address@hidden> writes:

> > > Would adding an optional argument that allows to specify an upper
> > > limit for the indexes the function looks at cover (all of) your
> > > concerns?

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

(be sure to eval with lexical-binding -> t).


Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]