-
Notifications
You must be signed in to change notification settings - Fork 429
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
Create Bag with initial elements #609
Conversation
Sources/Bag.swift
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Sources/Bag.swift
Outdated
} | ||
|
||
public init<S: Sequence>(_ elements: S) where S.Iterator.Element == Element { | ||
self.nextToken = Token(value: UInt64(elements.underestimatedCount)) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amended:+1:
Thanks for the PR! |
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