AlexanderM
(Alexander Momchilov)
July 21, 2023, 4:41pm
6
One concrete use case I've run into is to allow customization of my group(by:)
algorithm to allow callers to choose to use OrderedDictionary, or others:
I agree that ideally, the chainable Sequence methods would support returning an arbitrary Dictionary type, by e.g. taking the result type as an argument:
(0 ... 9).grouped(into: TreeDictionary<Int, Deque<Int>>.self) { $0 % 3 }
However, this is currently blocked on the lack of a mutable DictionaryProtocol
. We now have enough examples of dictionary types to start designing dictionary protocols (likely starting by prototyping them within swift-collections), but until we get that done, we should follow the stdlib's existing practice of simply returning the canonical type, which is Dictionary
in this case -- as @AlexanderM suggests in their original post.
7 Likes