Skip to content

Instantly share code, notes, and snippets.

@vakhidbetrakhmadov
Created August 19, 2019 10:23
Show Gist options
  • Save vakhidbetrakhmadov/20985790b3759ee017d1e8c64b55abae to your computer and use it in GitHub Desktop.
Save vakhidbetrakhmadov/20985790b3759ee017d1e8c64b55abae to your computer and use it in GitHub Desktop.
extension Sequence {
func grouped<T: Hashable>(by keyPath: KeyPath<Element, T>) -> [T: [Element]] {
return .init(grouping: self, by: { $0[keyPath: keyPath] })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment