Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add +combineLatest: #44

Closed

Conversation

bvanderveen
Copy link
Contributor

+combineLatest: is the same as -combineLatest:reduce:, where the reduce defaults to the identity function.

Per github/ReactiveCocoa#43.

… the reduce defaults to the identity function.
@jspahrsummers
Copy link
Member

This is looking good. Do you mind adding a unit test as well?

@ghost ghost assigned jspahrsummers Aug 28, 2012
@bvanderveen
Copy link
Contributor Author

I was hoping you'd ask. ;) I'm in the midst of downloading OS X 10.8 so I
can compile the test suite. :S

On Mon, Aug 27, 2012 at 6:08 PM, Justin Spahr-Summers <
notifications@github.com> wrote:

This is looking good. Do you mind adding a unit test as well?


Reply to this email directly or view it on GitHubhttps://github.com/github/ReactiveCocoa/pull/44#issuecomment-8076406.

@jspahrsummers
Copy link
Member

Does it not work on 10.7?

@bvanderveen
Copy link
Contributor Author

Not for me. Tried twiddling Base SDK and compiler settings but no go.

changed the behavior slightly so that it will yield multiple successive tuples of 'latest' values from source subscribables. this change required re-initializing the lastValues pointer, which was previously being used as a synchronization gate; a new gate object is introduced to synchronize calls to onNext.
@bvanderveen
Copy link
Contributor Author

I have added a commit with tests.

@@ -406,7 +407,7 @@ + (RACSubscribable *)combineLatest:(NSArray *)subscribables reduce:(id (^)(RACTu
for(id<RACSubscribable> o in subscribables) {
[orderedValues addObject:[lastValues objectForKey:[NSString stringWithFormat:@"%p", o]]];
}

lastValues = [NSMutableDictionary dictionaryWithCapacity:subscribables.count];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just use [lastValues removeAllObjects], which would remove any need for the nextGate variable used here.

@jspahrsummers
Copy link
Member

Almost there. Added an additional note.

…ar the dictionary rather than re-assign the pointer with a newly allocated dictionary
@bvanderveen
Copy link
Contributor Author

Good catch. Thanks!

…t want to assume the compiler will set them to nil!
@jspahrsummers
Copy link
Member

🤘✨⚡🚢

@bvanderveen
Copy link
Contributor Author

I just snuck one more minor commit in—could you take a look at it?

@jspahrsummers
Copy link
Member

@bvanderveen I appreciate the thoroughness; however, object variables are default-initialized to nil under ARC:

Initialization occurs when an object's lifetime begins, which depends on its storage duration. Initialization proceeds in two stages:

First, a null pointer is stored into the lvalue using primitive semantics. This step is skipped if the object is __unsafe_unretained.
Second, if the object has an initializer, that expression is evaluated and then assigned into the object using the usual assignment semantics.

@bvanderveen
Copy link
Contributor Author

True. Figured it was better to be explicit, but it's your call. :)

@jspahrsummers
Copy link
Member

Any removal of boilerplate is 👍 to me, so I'd like to leave it out.

@bvanderveen
Copy link
Contributor Author

Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants