Skip to content

Instantly share code, notes, and snippets.

@ikesyo
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikesyo/2e192261ec265239cd86 to your computer and use it in GitHub Desktop.
Save ikesyo/2e192261ec265239cd86 to your computer and use it in GitHub Desktop.
RAC: map: and flattenMap:
RACSignal *numberSignal = @[ @1, @2, @3 ].rac_sequence.signal;
// signal of @2, @4, @6
[numberSignal map:^ id (NSNumber number) {
return @(number.integerValue * 2);
}];
// signal of something like
// @{ @"id": @1, @"name": @"Name 1" },
// @{ @"id": @2, @"name": @"Name 2" },
// @{ @"id": @3, @"name": @"Name 3" }
[numberSignal flattenMap:^ RACSignal * (NSNumber number) {
// -fetchUserWithId: returns a signal that fetches some JSON from web API
return [client fetchUserWithId:number.integerValue];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment