Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Last active September 17, 2020 02:24
Show Gist options
  • Save tonyarnold/e45aafbc1df8e7965293ec1241263d35 to your computer and use it in GitHub Desktop.
Save tonyarnold/e45aafbc1df8e7965293ec1241263d35 to your computer and use it in GitHub Desktop.
Useful extension for storing a sequence of AnyCancellable instances
import Combine
import Combine
extension Sequence where Element == AnyCancellable {
/// Stores this type-erasing cancellable collection in the specified collection.
///
/// - Parameter collection: The collection in which to store this ``AnyCancellable`` sequence.
func store<C>(in collection: inout C) where C: RangeReplaceableCollection, C.Element == Element {
forEach { $0.store(in: &collection) }
}
/// Stores this type-erasing cancellable collection in the specified set.
///
/// - Parameter set: The set in which to store this ``AnyCancellable`` sequence.
func store(in set: inout Set<Element>) {
forEach { $0.store(in: &set) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment