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

Conditionally conform Chain2Sequence to MutableCollection #217

Open
ffried opened this issue Dec 19, 2023 · 1 comment
Open

Conditionally conform Chain2Sequence to MutableCollection #217

ffried opened this issue Dec 19, 2023 · 1 comment

Comments

@ffried
Copy link

ffried commented Dec 19, 2023

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.

@natecook1000
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants