Implement drop, take & filter extension functions for UArrays

This commit is contained in:
Abduqodiri Qurbonzoda
2019-02-15 15:45:39 +03:00
committed by Ilya Gorbunov
parent abb275775e
commit c42dbb34ca
4 changed files with 973 additions and 17 deletions
@@ -39,7 +39,7 @@ object Filtering : TemplateGroupBase() {
val f_drop = fn("drop(n: Int)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
val n = "\$n"
doc {
@@ -115,7 +115,7 @@ object Filtering : TemplateGroupBase() {
"""
}
body(ArraysOfObjects, ArraysOfPrimitives) {
body(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
"""
require(n >= 0) { "Requested element count $n is less than zero." }
return takeLast((size - n).coerceAtLeast(0))
@@ -125,7 +125,7 @@ object Filtering : TemplateGroupBase() {
val f_take = fn("take(n: Int)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
val n = "\$n"
doc {
@@ -185,7 +185,7 @@ object Filtering : TemplateGroupBase() {
"""
}
body(ArraysOfObjects, ArraysOfPrimitives) {
body(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
"""
require(n >= 0) { "Requested element count $n is less than zero." }
if (n == 0) return emptyList()
@@ -204,7 +204,7 @@ object Filtering : TemplateGroupBase() {
}
val f_dropLast = fn("dropLast(n: Int)") {
include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings)
include(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences, Strings)
} builder {
val n = "\$n"
@@ -234,7 +234,7 @@ object Filtering : TemplateGroupBase() {
}
val f_takeLast = fn("takeLast(n: Int)") {
include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings)
include(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences, Strings)
} builder {
val n = "\$n"
doc {
@@ -262,7 +262,7 @@ object Filtering : TemplateGroupBase() {
"""
}
body(ArraysOfObjects, ArraysOfPrimitives) {
body(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
"""
require(n >= 0) { "Requested element count $n is less than zero." }
if (n == 0) return emptyList()
@@ -299,9 +299,10 @@ object Filtering : TemplateGroupBase() {
val f_dropWhile = fn("dropWhile(predicate: (T) -> Boolean)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc {
"""
@@ -355,9 +356,10 @@ object Filtering : TemplateGroupBase() {
val f_takeWhile = fn("takeWhile(predicate: (T) -> Boolean)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc {
"""
@@ -406,9 +408,11 @@ object Filtering : TemplateGroupBase() {
}
val f_dropLastWhile = fn("dropLastWhile(predicate: (T) -> Boolean)") {
include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings)
include(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences, Strings)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc {
"""
Returns a list containing all elements except last elements that satisfy the given [predicate].
@@ -462,9 +466,11 @@ object Filtering : TemplateGroupBase() {
}
val f_takeLastWhile = fn("takeLastWhile(predicate: (T) -> Boolean)") {
include(Lists, ArraysOfObjects, ArraysOfPrimitives, CharSequences, Strings)
include(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences, Strings)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc {
"""
Returns a list containing last elements satisfying the given [predicate].
@@ -528,9 +534,10 @@ object Filtering : TemplateGroupBase() {
val f_filter = fn("filter(predicate: (T) -> Boolean)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Returns a ${f.mapResult} containing only ${f.element.pluralize()} matching the given [predicate]." }
returns("List<T>")
@@ -555,9 +562,10 @@ object Filtering : TemplateGroupBase() {
val f_filterTo = fn("filterTo(destination: C, predicate: (T) -> Boolean)") {
includeDefault()
include(CharSequences)
include(CharSequences, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Appends all ${f.element.pluralize()} matching the given [predicate] to the given [destination]." }
typeParam("C : TCollection")
@@ -583,9 +591,10 @@ object Filtering : TemplateGroupBase() {
val f_filterIndexed = fn("filterIndexed(predicate: (index: Int, T) -> Boolean)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc {
"""
@@ -627,9 +636,10 @@ object Filtering : TemplateGroupBase() {
val f_filterIndexedTo = fn("filterIndexedTo(destination: C, predicate: (index: Int, T) -> Boolean)") {
includeDefault()
include(CharSequences)
include(CharSequences, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc {
"""
@@ -652,9 +662,10 @@ object Filtering : TemplateGroupBase() {
val f_filterNot = fn("filterNot(predicate: (T) -> Boolean)") {
includeDefault()
include(CharSequences, Strings)
include(CharSequences, Strings, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Returns a list containing all elements not matching the given [predicate]." }
returns("List<T>")
@@ -680,9 +691,10 @@ object Filtering : TemplateGroupBase() {
val f_filterNotTo = fn("filterNotTo(destination: C, predicate: (T) -> Boolean)") {
includeDefault()
include(CharSequences)
include(CharSequences, ArraysOfUnsigned)
} builder {
inline()
specialFor(ArraysOfUnsigned) { inlineOnly() }
doc { "Appends all elements not matching the given [predicate] to the given [destination]." }
typeParam("C : TCollection")