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

Create Bag with initial elements #609

Merged
merged 7 commits into from
Feb 20, 2018

Conversation

ra1028
Copy link
Contributor

@ra1028 ra1028 commented Feb 19, 2018

Hi✋
I made it possible to create Bag with initial elements, and CompositeDisposable also improved accordingly.
Probably conflicts with #608, but I fix after either is merged.

Checklist

  • Updated CHANGELOG.md.

public init<S: Sequence>(_ elements: S) where S.Iterator.Element == Element {
nextToken = Token(value: UInt64(elements.underestimatedCount))
tokens = ContiguousArray(0..<nextToken.value)
self.elements = ContiguousArray(elements)
Copy link
Member

Choose a reason for hiding this comment

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

Be consistent here: either self for all or none.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do.
elements is used as a parameter name, so I'll add self to all.

bag.insert(disposable)
}

let bag = Bag(disposables)
Copy link
Member

Choose a reason for hiding this comment

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

👍

}

public init<S: Sequence>(_ elements: S) where S.Iterator.Element == Element {
self.nextToken = Token(value: UInt64(elements.underestimatedCount))
Copy link
Member

Choose a reason for hiding this comment

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

underestimatedCount is not guaranteed to equal the exact number of elements. We should derive this from the ContiguousArray constructed from elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Amended:+1:

@mdiep
Copy link
Contributor

mdiep commented Feb 20, 2018

Thanks for the PR!

@mdiep mdiep merged commit d9169cb into ReactiveCocoa:master Feb 20, 2018
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

4 participants