// a copy of the f# fib implementation
func fib(n : Int) -> Int {
if n == 0 || n == 1 {
return n
}
else {
return fib(n - 1) + fib(n - 2)
}
}
// A simple print output function
let output = {(n: Array<Int>) -> () in
for (index,value) in enumerate(n) {
println("[\(index)] is \(value)")
}
}
// Take an array of Ints, run fib on each in turn, filter just those %2 and then output the result
<p class="indent">[1,2,3,4,5,6,7,8,9,10]
|> map(fib)
|> filter({$0 % 2 == 0})
|> output
<p class="indent">