Skip to content

Conditionally conform Chain2Sequence to MutableCollection #217

Open

Description

@ffried

Is there a specific reason why Chain2Sequence does not conform to MutableCollection when Base1 and Base2 do?

I'm trying to build an API that uses two some MutableCollection<T> as parameters and one as return value. I need it to be mutable, because I need to change a specific element in the collection. Internally, the parameters will be chained using chain(_:_:) - or at least that's the goal.

I'm happy to provide a PR for this, but I wanted to see if there's a reason against it first.

Activity

  1. natecook1000 commented on Dec 22, 2023

    @natecook1000
    Member

    These kinds of wrapper collections typically aren't mutable – for example, when you called reversed() on an array, the elements of the resulting ReversedCollection aren't mutable, even if your original array is.

    That said, I don't think it's necessarily the wrong thing to do here – in general the first mutation will make a copy of whichever base collection ends up getting modified, and from then it will be singly referenced. I've started a discussion in the forums to talk about the question – please add any more thoughts you have: https://forums.swift.org/t/making-collection-wrappers-mutable/69142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions