Add the onEach extension function to the Array #KT-28290

This commit is contained in:
Abduqodiri Qurbonzoda
2020-04-01 00:34:52 +03:00
parent 8531c1e9a5
commit 508d0edd6d
5 changed files with 164 additions and 2 deletions
@@ -1567,13 +1567,21 @@ object Aggregates : TemplateGroupBase() {
}
val f_onEach = fn("onEach(action: (T) -> Unit)") {
include(Iterables, Maps, CharSequences, Sequences)
includeDefault()
include(Maps, CharSequences, ArraysOfUnsigned)
} builder {
since("1.1")
doc { "Performs the given [action] on each ${f.element} and returns the ${f.collection} itself afterwards." }
specialFor(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
since("1.4")
inlineOnly()
returns("SELF")
body { "return apply { for (element in this) action(element) }" }
}
specialFor(Iterables, Maps, CharSequences) {
inline()
doc { "Performs the given [action] on each ${f.element} and returns the ${f.collection} itself afterwards." }
val collectionType = when (f) {
Maps -> "M"
CharSequences -> "S"