Swift: add Array.each (and here's why…)
| Originator: | radexpl | ||
| Number: | rdar://17716661 | Date Originated: | |
| Status: | Resolved: | ||
| Product: | Product Version: | ||
| Classification: | Reproducible: |
Hi. I think you should add `each` method to collection types. I realize that Chris Lattner (IIRC) said on ADF that it's not really needed as you can just use for..in, but here's why I think `each` is useful:
You can chain `each` with operations such as `filter` and `map` in a much more elegant way, like so:
[1, 4, 7].map { $0 * 5 }.filter { $0 > 10 }.each { println($0) }
Very nice, very expressive. Sweet like Ruby. Compare to:
let filtered_nums = [1, 4, 7].map { $0 * 5 }.filter { $0 > 10 }
for num in filtered_nums {
println(num)
}
Functional-style maps and filters combined with ObjC-style for. Meh.
Thanks for your consideration.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!