standard library: added isEmpty/isNotEmpty functions for primitive arrays

This commit is contained in:
nik
2013-12-01 15:02:45 +04:00
committed by Evgeny Gerashchenko
parent b636538422
commit 45e9211943
12 changed files with 171 additions and 6 deletions
@@ -32,19 +32,19 @@ fun main(args: Array<String>) {
buildFor(Iterators, null)
}
val iterables = iterables()
val arrays = arrays()
val sumFunctions = PrimitiveType.values().map(::sumFunction).filterNotNull()
(iterables + sumFunctions).writeTo(File(outDir, "_Arrays.kt")) {
(arrays + sumFunctions).writeTo(File(outDir, "_Arrays.kt")) {
buildFor(Arrays, null)
}
for (primitive in PrimitiveType.values()) {
(iterables + sumFunction(primitive)).filterNotNull().writeTo(File(outDir, "_${primitive.name}Arrays.kt")) {
(arrays + sumFunction(primitive)).filterNotNull().writeTo(File(outDir, "_${primitive.name}Arrays.kt")) {
buildFor(PrimitiveArrays, primitive)
}
}
(iterables + sumFunctions).writeTo(File(outDir, "_Iterables.kt")) {
(iterables().sort() + sumFunctions).writeTo(File(outDir, "_Iterables.kt")) {
buildFor(Iterables, null)
}
@@ -0,0 +1,29 @@
package templates
import templates.Family.*
fun arrays(): List<GenericFunction> {
val templates = iterables()
templates add f("isEmpty()") {
absentFor(Arrays)
isInline = false
doc = "Returns true if the array is empty"
returns("Boolean")
body {
"return size == 0"
}
}
templates add f("isNotEmpty()") {
absentFor(Arrays)
isInline = false
doc = "Returns true if the array is empty"
returns("Boolean")
body {
"return !isEmpty()"
}
}
return templates.sort()
}
@@ -3,7 +3,7 @@ package templates
import java.util.ArrayList
import templates.Family.*
fun iterables(): List<GenericFunction> {
fun iterables(): ArrayList<GenericFunction> {
val templates = commons()
@@ -140,5 +140,5 @@ fun iterables(): List<GenericFunction> {
}
}
return templates.sort()
return templates
}