[CLJ-1124] for-as Created: 10/Dec/12 Updated: 18/Apr/14 Resolved: 18/Apr/14
|Affects Version/s:||Release 1.5|
A common pattern in programming is building up some data structure step by step:
In an imperative for loop this is easy since we have easy access to the "current" data structure being built up.
I propose the addition of a function for-as similar to as-> except the value of the last loop iteration is bound to the name.
So we can write the above as:
An (un-optimized) implementation might be something like:
Note: reduce-for does not return a seq, instead it returns the result of the last loop body iteration.
|Comment by Kevin Downey [ 18/Apr/14 1:30 AM ]|
this is not super clear to me, but it seems like a request for a `for` like macro for reduce.
|Comment by Alex Miller [ 18/Apr/14 7:18 AM ]|
This case seems adequately handled by reduce or loop/recur. I don't think the proposal is compelling enough to consider adding to core.