Last active
July 8, 2020 09:51
-
-
Save mehmetfarhan/637ea9a2ce20b0585c629b084561d4f8 to your computer and use it in GitHub Desktop.
group
This file contains 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
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