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

Provide an OrderedSet.filter operation; currently the Sequence one is used thus an Array is returned #158

Closed
ktoso opened this issue Aug 16, 2022 · 0 comments · Fixed by #159
Labels
enhancement New feature or request
Milestone

Comments

@ktoso
Copy link
Member

ktoso commented Aug 16, 2022

I'm moving some code to use OrderedSet and noticed it is missing a filter operation.

Previous code:

            // 1) we remove any registrations that it hosted
            let registrations: Set<VersionedRegistration> = self._registrations.removeValue(forKey: key) ?? []
            let remainingRegistrations: Set<VersionedRegistration> = registrations.filter { registration in
                registration.actorID.uniqueNode != node
            }

this was ok, since we call the filter on:

extension Set {
    @available(swift 4.0)
    @inlinable public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> Set<Element>
}

but it seems that OrderedSet is missing this specialization, so we fallback to calling the Sequence's impl:

    @inlinable public func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> [Self.Element]

returning an array -- which is a bit meh, since we have to convert back into the OrderedSet.

Feature Request

Please provide a filter similar to how Set does that keeps the collection type OrderedSet -> OrderedSet

@ktoso ktoso added the enhancement New feature or request label Aug 16, 2022
ktoso added a commit to ktoso/swift-collections that referenced this issue Aug 16, 2022
@ktoso ktoso mentioned this issue Aug 16, 2022
7 tasks
lorentey added a commit that referenced this issue Aug 17, 2022
@lorentey lorentey added this to the 1.1.0 milestone Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants