Last active
December 17, 2015 22:49
-
-
Save v6ak/5685310 to your computer and use it in GitHub Desktop.
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
| // Prakticky neupravená verze. (Stejná logika jako původní Javový kód, proto imperativní.) | |
| def partitionBy[T, K](inputList: Iterable[T], partitionFunc: T=>K) = { | |
| val multimap = HashMultimap[K, T]() | |
| for (t <- inputList) { | |
| multimap(partitionFunc(t)) = t | |
| } | |
| multimap | |
| } | |
| // Funkcionální verze | |
| def partitionBy[T, K](inputList: Iterable[T], partitionFunc: T=>K>): Multimap<K, T> = HashMultimap( | |
| for(t <- inputList) yield partitionFunc(t) -> t | |
| : _*) // kvůli varargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment