Skip to content

Instantly share code, notes, and snippets.

@mehmetfarhan
Last active July 8, 2020 09:51
Show Gist options
  • Save mehmetfarhan/637ea9a2ce20b0585c629b084561d4f8 to your computer and use it in GitHub Desktop.
Save mehmetfarhan/637ea9a2ce20b0585c629b084561d4f8 to your computer and use it in GitHub Desktop.
group
public extension Sequence {
func group<K: Hashable & Comparable>(by keyForValue: (Element) -> K) -> [[Element]] {
return Dictionary(grouping: self, by: keyForValue).sorted { $0.key < $1.key }.map { $0.value }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment