Skip to content

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

@ktoso

Description

@ktoso

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions