dash.el
dash.el copied to clipboard
Implement -dolist
Fixes #136
The syntax is as follows
(-dolist ((first . second) '((a . b) (c . d)))
(message "first %s second %s" first second))
;; also works as usual `dolist'
(-dolist (var '((a . b) (c . d)))
(message "first %s" var))
I like the syntax but in all honesty I think I never in my life used dolist so I'm not sure if it's worth adding this.
How about the name -each-let? That fits quite nicely with -when-let etc.
As an aside, dolist is awesome when you want nested loops.
(dolist (team world-cup)
(dolist (player team)
(foo player)))
Compare this with:
(--each world-cup
(--each it
(foo it)))
This is confusing because it means different things on line 2 vs line 3. There's also no way to refer back to the outer it (which I've named team in the first example).
I don't like that cl advises dolist, and I think dolist's optional result argument is less readable, but the basic use case is really handy.
Yea, so we can view dolist is like an --each with named it. Which I think -each-let represents nicely. I think I'll go with that, thanks!
--each-as anyone? (cf. -as->)
(just thinking out loud)