From: Tim Landscheidt <tim@tim-landscheidt.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Doing something different for the last element of a sequence (partition)?
Date: Mon, 16 Nov 2020 11:40:37 +0000 [thread overview]
Message-ID: <878sb1edhm.fsf@passepartout.tim-landscheidt.de> (raw)
In-Reply-To: X7JeFVHX7mFLgdKb@scrozzle
2QdxY4RzWzUUiLuE@potatochowder.com wrote:
>> I have a list of URLs (all-urls) and I want to launch a
>> Firefox window for the first x URLs, then wait y seconds,
>> then launch another one, etc., and then prompt the user if
>> the source of URLs can be deleted (provided that everything
>> went smoothly).
>> If I do:
>> | (seq-doseq (firefox-urls (seq-partition (seq-sort all-urls #'string<) x))
>> | (apply 'call-process "firefox" nil "*firefox*" nil firefox-urls)
>> | (sleep-for y))
>> that works fine, except that it also waits for y seconds af-
>> ter the last launch.
> Or handle the first one as the special case (completely untested):
> (cl-do (((firefox-urls (seq-partition (seq-sort all-urls #'string<) x))
> (delay 0 y)))
> (sleep-for delay)
> (apply 'call-process "firefox" nil "*firefox*" nil firefox-urls))
Inspiration! I initially looked at seq-reduce, but dismiss-
ed it because I was focussing on the /last/ partition. But
it is rather simple:
| (let
| ((all-urls (mapcar 'number-to-string (number-sequence 1 25))))
| (message "all-urls = %S" all-urls)
| (seq-reduce
| (lambda (not-first-call firefox-urls)
| (if not-first-call
| (message "Would sleep"))
| (message "firefox-urls = %S" firefox-urls)
| t) ;; Set not-first-call for subsequent calls.
| (seq-partition (seq-sort #'string< all-urls) 3)
| nil))
Thanks!
Tim
prev parent reply other threads:[~2020-11-16 11:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 10:28 Doing something different for the last element of a sequence (partition)? Tim Landscheidt
2020-11-16 11:10 ` 2QdxY4RzWzUUiLuE
2020-11-16 11:40 ` Tim Landscheidt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878sb1edhm.fsf@passepartout.tim-landscheidt.de \
--to=tim@tim-landscheidt.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).