Open ilyash-b opened 1 year ago
Yet another alternative (also a possible design, not implemented) I was thinking about previously but forgot to mention above:
for url in list1, info in list2 {
...
}
Inspired by loop facility in Common Lisp: https://lispcookbook.github.io/cl-cookbook/iteration.html (search for "Looping over two lists in parallel")
The problem
From a user:
Assignment to
url
andinfo
are verbose.Possible Solutions
List of solutions that came to mind. To be evaluated.
De-structuring
Described in #239
Something like
for [url, info] in zip(list1, list2)
zip(..., Fun)
zip(list1, list2, F(url, info) ...)
and in generalzip(list1, ..., listN, F(arg1, ..., argN) ...)
each(Zip, Fun)
Note:
Zip
type would be a new typeeach(Zip(list1, list2), F(url, info) ...)
Advantage:
map(Zip(...), ...)
should also work out of the box.each_spread()
Downside: map() won't work so map_spread() should be introduced.
each_spread(zip(list1, list2), F(url, info) ...)
Implementation:
Pattern matching (related to de-structuring)
With sample syntax:
entry =~ [@url, @info]
Workaround for exactly 2 Arrs
Workaround creates intermediate
Hash
.each(Hash, Fun)
calls the callback with 2 arguments (key and value).