Filter: Difference between revisions

m
Line 1,134:
Idiomatic approach in Dy is to use non-strict iterators (which can be combined without intermedate data structures) and translate the result to an array if needed:
 
<lang Dyalect>func Iterator.filterFilter(pred) {
for x in this when pred(x) {
yield x
Line 1,140:
}
 
func Iterator.selectSelect(proj) {
for x in this {
yield proj(x)
Line 1,147:
 
var xs = [1..20]
var arr = xs.iterIterate().filterFilter(x => x % 2 == 0).selectSelect(x => x.toStringToString())
print(arr.toArrayToArray())</lang>
 
{{out}}
Anonymous user