RosettaCodeData/Task/Apply-a-callback-to-an-array/Dyalect/apply-a-callback-to-an-array.dyalect

13 lines
195 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
func Array.Select(pred) {
let ys = []
for x in this when pred(x) {
ys.Add(x)
}
return ys
}
var arr = [1, 2, 3, 4, 5]
var squares = arr.Select(x => x * x)
print(squares)