renamed the rather long getOrElseUpdate to a simpler getOrPut which is a bit simpler and more accurate; as a new entry is put into the Map if its null

This commit is contained in:
James Strachan
2012-02-21 11:11:43 +00:00
parent 724f7860ab
commit a68b00dfd4
4 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -110,7 +110,7 @@ inline fun <T> java.lang.Iterable<T>.foldRight(initial: T, operation: (it: T, it
inline fun <T,K> java.lang.Iterable<T>.groupBy(result: Map<K,List<T>> = HashMap<K,List<T>>(), toKey: (T)-> K) : Map<K,List<T>> {
for (elem in this) {
val key = toKey(elem)
val list = result.getOrElseUpdate(key){ ArrayList<T>() }
val list = result.getOrPut(key){ ArrayList<T>() }
list.add(elem)
}
return result