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
IdentifiedArrayby custom initializers onRangeReplaceableCollectionthat take a_(Mutable)IdentifiedCollection.I wondered if it would be possible to implement similar initializers that take either
Collections ofIdentifiableElements, or aCollectionand aKeyPath<Element, ID>, like theForEachinitializers from SwiftUI.I sketched the following:
Do these implementations seem valid?
I think (?) the dictionary mapping
IDs toIndexes is kind of a lightweight version of what SwiftUI'sForEachdoes when it creates thisIndexedIdentifierCollectioninternally. 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)IdentifiedCollectioninitializers, which have theIDsat 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
SharedReadercounterparts. And you could drop the swift-algorithms dependency and justziptheIDs andIndexes.)Any thoughts? Would these initializers be generally useful? Are there other ways to go about this than
RangeReplaceableCollectioninitializers?Beta Was this translation helpful? Give feedback.
All reactions