fn map(array: @Array<'T>, f: (@'T) => 'G) -> Array<'G> { let res: Array<'G> = arr<'G>(); for i in array { res.push<'G>(f<@'T, 'G>(i)); } return *>res; } fn filter(array: @Array<'T>, f: (@'T) => Bool) -> Array<'T> { let res: Array<'T> = arr<'T>(); for i in array { if f<@'T, Bool>(i) { res.push<'T>(*<'T>i); } } return *>res; } let a: Array = arr(); a.push(1); a.push(2); a.push(3); a.push(4); a.push(5); let b: Array = a.map((n: @Int) -> Int n * 2); let c: Array = a.map((n: @Int) -> Bool n > 2); if b[0] != 2 || b[1] != 4 || b[2] != 6 || b[3] != 8 || b[4] != 10 { panic("Invalid array contents"); } if *c[0] || *c[1] || !*c[2] || !*c[3] || !*c[4] { panic("Invalid array contents"); } let d: Array = a.filter((n: @Int) -> Bool n % 2 == 0); if d[0] != 2 || d[1] != 4 { panic("Invalid array contents"); }