Filter: Difference between revisions

170 bytes removed ,  2 years ago
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>funcvar Iterator.Filter(pred)xs {= [1..20]
var arr = xs.Iterate().Filter(x => x % 2 == 0).SelectMap(x => x.ToString())
for x in this when pred(x) {
yield x
}
}
 
func Iterator.Select(proj) {
for x in this {
yield proj(x)
}
}
 
var xs = [1..20]
var arr = xs.Iterate().Filter(x => x % 2 == 0).Select(x => x.ToString())
print(arr.ToArray())</lang>
 
Anonymous user