OrderedSet append(contentsOf:)
with insertion check result/results
#329
Labels
enhancement
New feature or request
Motivation
I am essentially using
OrderedSet
as the data source for aUICollectionView
wrapper. In said wrapper, I allow passing in anOrderedSet
, but I would also like to allow passing in anySequence
(whereElement: Hashable
) where I would instead create the necessaryOrderedSet
. Additionally, I would like to log a warning if the given sequence contained duplicates and will result in unexpected behavior, similar to SwiftUI's warnings withForEach/etc
.Problem
Currently,
append(contentsOf:)
doesn't return any insertion results likeappend
does. I think that generally this would be helpful.Design
The basic idea can be done with the new function
append(checkingContentsOf:)
:However that can be a bit heavy for unexpected long sequences and I would have to iterate over the results for duplication check. So instead we can just check instead if the given sequence contained any duplicates:
I propose that one of these, or something similar, be implemented on
OrderedSet
or that the currentappend(contentsOf:)
gains a discardable return result.The text was updated successfully, but these errors were encountered: