KEEP-23 implement group and fold operations
Docs for group-and-fold operations Fix implementation for countEach and sumEachBy countEach and sumEachBy implementations for JS Rename keySelector to keyOf Generate additional sources for groupingBy + headers Rename countEach and sumEachBy to eachCount and eachSumOf.
This commit is contained in:
@@ -388,5 +388,32 @@ fun mapping(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("groupingBy(crossinline keySelector: (T) -> K)") {
|
||||
since("1.1")
|
||||
inline(true)
|
||||
only(Iterables, Sequences, ArraysOfObjects, CharSequences)
|
||||
|
||||
typeParam("T")
|
||||
typeParam("K")
|
||||
|
||||
returns("Grouping<T, K>")
|
||||
|
||||
doc { f ->
|
||||
"""
|
||||
Creates a [Grouping] source from ${f.collection.prefixWithArticle()} to be used later with one of group-and-fold operations
|
||||
using the specified [keySelector] function to extract a key from each ${f.element}.
|
||||
"""
|
||||
}
|
||||
|
||||
body {
|
||||
"""
|
||||
return object : Grouping<T, K> {
|
||||
override fun elementIterator(): Iterator<T> = this@groupingBy.iterator()
|
||||
override fun keyOf(element: T): K = keySelector(element)
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
return templates
|
||||
}
|
||||
Reference in New Issue
Block a user