Skip to content

Instantly share code, notes, and snippets.

@dudarenko-io
Last active August 24, 2017 14:08
Show Gist options
  • Save dudarenko-io/eda8b060355f410122aa0bb75b326242 to your computer and use it in GitHub Desktop.
Save dudarenko-io/eda8b060355f410122aa0bb75b326242 to your computer and use it in GitHub Desktop.
extension Dictionary where Value: Collection {
/// A Boolean value indicating whether all collection-values in dictionary is empty.
var isContentsEmpty: Bool {
for collection in values where !collection.isEmpty {
return false
}
return true
}
}
extension Dictionary where Value: Collection, Value.IndexDistance == Int {
/// The number of elements in all dictionary`s values-collections.
var totalCount: Int {
return self.reduce(0) { (count, keyValue) -> Int in
count + keyValue.value.count
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment