Add onEachIndexed similar to forEachIndexed #KT-37161
This commit is contained in:
+4
@@ -2152,6 +2152,7 @@ public final class kotlin/collections/CollectionsKt {
|
||||
public static final fun none (Ljava/lang/Iterable;)Z
|
||||
public static final fun none (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Z
|
||||
public static final fun onEach (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Iterable;
|
||||
public static final fun onEachIndexed (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/lang/Iterable;
|
||||
public static final fun partition (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair;
|
||||
public static final fun plus (Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
|
||||
public static final fun plus (Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/util/List;
|
||||
@@ -2369,6 +2370,7 @@ public final class kotlin/collections/MapsKt {
|
||||
public static final fun none (Ljava/util/Map;)Z
|
||||
public static final fun none (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Z
|
||||
public static final fun onEach (Ljava/util/Map;Lkotlin/jvm/functions/Function1;)Ljava/util/Map;
|
||||
public static final fun onEachIndexed (Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Ljava/util/Map;
|
||||
public static final fun plus (Ljava/util/Map;Ljava/lang/Iterable;)Ljava/util/Map;
|
||||
public static final fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
|
||||
public static final fun plus (Ljava/util/Map;Lkotlin/Pair;)Ljava/util/Map;
|
||||
@@ -4724,6 +4726,7 @@ public final class kotlin/sequences/SequencesKt {
|
||||
public static final fun none (Lkotlin/sequences/Sequence;)Z
|
||||
public static final fun none (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Z
|
||||
public static final fun onEach (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
|
||||
public static final fun onEachIndexed (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence;
|
||||
public static final fun partition (Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/Pair;
|
||||
public static final fun plus (Lkotlin/sequences/Sequence;Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
|
||||
public static final fun plus (Lkotlin/sequences/Sequence;Ljava/lang/Object;)Lkotlin/sequences/Sequence;
|
||||
@@ -5116,6 +5119,7 @@ public final class kotlin/text/StringsKt {
|
||||
public static final fun none (Ljava/lang/CharSequence;)Z
|
||||
public static final fun none (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Z
|
||||
public static final fun onEach (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function1;)Ljava/lang/CharSequence;
|
||||
public static final fun onEachIndexed (Ljava/lang/CharSequence;Lkotlin/jvm/functions/Function2;)Ljava/lang/CharSequence;
|
||||
public static final fun padEnd (Ljava/lang/CharSequence;IC)Ljava/lang/CharSequence;
|
||||
public static final fun padEnd (Ljava/lang/String;IC)Ljava/lang/String;
|
||||
public static synthetic fun padEnd$default (Ljava/lang/CharSequence;ICILjava/lang/Object;)Ljava/lang/CharSequence;
|
||||
|
||||
@@ -1609,6 +1609,61 @@ object Aggregates : TemplateGroupBase() {
|
||||
}
|
||||
}
|
||||
|
||||
val f_onEachIndexed = fn("onEachIndexed(action: (index: Int, T) -> Unit)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
since("1.4")
|
||||
|
||||
doc {
|
||||
"""
|
||||
Performs the given [action] on each ${f.element}, providing sequential index with the ${f.element},
|
||||
and returns the ${f.collection} itself afterwards.
|
||||
@param [action] function that takes the index of ${f.element.prefixWithArticle()} and the ${f.element} itself
|
||||
and performs the action on the ${f.element}.
|
||||
"""
|
||||
}
|
||||
|
||||
specialFor(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
inlineOnly()
|
||||
returns("SELF")
|
||||
body { "return apply { forEachIndexed(action) }" }
|
||||
}
|
||||
|
||||
specialFor(Maps, Iterables, CharSequences) {
|
||||
inline()
|
||||
val collectionType = when (f) {
|
||||
Maps -> "M"
|
||||
CharSequences -> "S"
|
||||
else -> "C"
|
||||
}
|
||||
receiver(collectionType)
|
||||
returns(collectionType)
|
||||
typeParam("$collectionType : SELF")
|
||||
body { "return apply { ${if (f == Maps) "entries." else ""}forEachIndexed(action) }" }
|
||||
}
|
||||
|
||||
specialFor(Sequences) {
|
||||
returns("SELF")
|
||||
doc {
|
||||
"""
|
||||
Returns a sequence which performs the given [action] on each ${f.element} of the original sequence as they pass through it.
|
||||
@param [action] function that takes the index of ${f.element.prefixWithArticle()} and the ${f.element} itself
|
||||
and performs the action on the ${f.element}.
|
||||
"""
|
||||
}
|
||||
sequenceClassification(intermediate, stateless)
|
||||
body {
|
||||
"""
|
||||
return mapIndexed { index, element ->
|
||||
action(index, element)
|
||||
element
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val f_forEach = fn("forEach(action: (T) -> Unit)") {
|
||||
includeDefault()
|
||||
include(Maps, CharSequences, ArraysOfUnsigned)
|
||||
@@ -1637,7 +1692,7 @@ object Aggregates : TemplateGroupBase() {
|
||||
"""
|
||||
Performs the given [action] on each ${f.element}, providing sequential index with the ${f.element}.
|
||||
@param [action] function that takes the index of ${f.element.prefixWithArticle()} and the ${f.element} itself
|
||||
and performs the desired action on the ${f.element}.
|
||||
and performs the action on the ${f.element}.
|
||||
""" }
|
||||
returns("Unit")
|
||||
body {
|
||||
|
||||
Reference in New Issue
Block a user