! RACSequence *fibTail(int n, int p, int m) { return [RACSequence sequenceWithHeadBlock:^NSNumber *{ return @(p); } tailBlock:^RACSequence *{ if (n == 1) { return [RACSequence empty]; } else { return fibTail(n - 1, m, p + m); } }]; } ! NSLog(@"%@", fib(4).array); // [1, 1, 2, 3] ! NSLog(@"%@", [fib(4) zipWith:[fib(4) map:^NSNumber *(NSNumber *value) { return @([value integerValue] * [value integerValue]); }]].array); // [(1, 1), (1, 1), (2, 4), (3, 9)] ! NSLog(@"%@", [fib(4) foldLeftWithStart:@0 reduce:^NSNumber *(NSNumber *accumulator, NSNumber *value) { return @(accumulator.integerValue + value.integerValue); }]); // 7