Open edemaine opened 1 year ago
Spreads could also apply to object results as well.
Another application would be the ability to flatten the results of nested for
loops. Ideally we could simplify the output to not construct an intermediate array, as follows:
array := for sublist of list
...for item of sublist
item ** 2
---
const array = (function(){const results = []
for (const sublist of list) {
for (const item of sublist) {
results.push(item ** 2)
}
}
})()
This gives us a very flexible equivalent of Janet's seq
primitive.
+1 on the object comprehensions: looks/feels totally natural, and with significant Python exposure prior to any Java/TypeScript, something I've been feeling the lack of basically since day 1.
Object comprehensions
(based on Python's dict comprehensions)
Array flattening via spreads
This could also be achieved via
for.value.push(...item); continue
given #362, but this seems like more natural notation.