Replies: 1 comment
-
At a glance this looks sound to me, but I'd be cautious with exotic uses of bindings and And so the main other concern you bring up is performance, where there is an extra data structure created, iterated over, and destroyed. Caveats aside, if you explore this further and discover anything interesting, please report back :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been wanting to experiment with deriving shared state of collections beyond
IdentifiedArray
(trees, etc).I see swift-sharing provides this functionality to
IdentifiedArray
by custom initializers onRangeReplaceableCollection
that take a_
(Mutable
)IdentifiedCollection
.I wondered if it would be possible to implement similar initializers that take either
Collection
s ofIdentifiable
Element
s, or aCollection
and aKeyPath<Element, ID>
, like theForEach
initializers from SwiftUI.I sketched the following:
Do these implementations seem valid?
I think (?) the dictionary mapping
ID
s toIndex
es is kind of a lightweight version of what SwiftUI'sForEach
does when it creates thisIndexedIdentifierCollection
internally. Alas, that type has no public initializers, and here we wouldn't want to depend on SwiftUI anyway. (Though that type is why I named the dictionary value such as I did, but I'm not wedded to it if there's something more sensible. Should it actually be ...identifiedIndexers
? 🤔 Not sure.)Slightly less efficient than the
_
(Mutable
)IdentifiedCollection
initializers, which have theIDs
at the ready and are subscriptable by them, but maybe an acceptable trade-off for allowing less specialized collections?(And of course you could create a pair of
SharedReader
counterparts. And you could drop the swift-algorithms dependency and justzip
theID
s andIndex
es.)Any thoughts? Would these initializers be generally useful? Are there other ways to go about this than
RangeReplaceableCollection
initializers?Beta Was this translation helpful? Give feedback.
All reactions