dash.el icon indicating copy to clipboard operation
dash.el copied to clipboard

Implement -dolist

Open Fuco1 opened this issue 7 years ago • 5 comments

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))

Fuco1 avatar Jul 26 '18 12:07 Fuco1

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.

Fuco1 avatar Jul 26 '18 12:07 Fuco1

How about the name -each-let? That fits quite nicely with -when-let etc.

Wilfred avatar Jul 26 '18 22:07 Wilfred

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.

Wilfred avatar Jul 26 '18 23:07 Wilfred

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!

Fuco1 avatar Jul 27 '18 10:07 Fuco1

--each-as anyone? (cf. -as->)

(just thinking out loud)

wbolster avatar Nov 12 '19 18:11 wbolster