Last active
September 17, 2020 02:24
-
-
Save tonyarnold/e45aafbc1df8e7965293ec1241263d35 to your computer and use it in GitHub Desktop.
Useful extension for storing a sequence of AnyCancellable instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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