Slice functions for arrays and lists.

This commit is contained in:
Ilya Ryzhenkov
2014-03-20 16:03:47 +04:00
committed by Andrey Breslav
parent aee199b5b0
commit 1db035a0aa
4 changed files with 162 additions and 1 deletions
@@ -264,5 +264,20 @@ fun filtering(): List<GenericFunction> {
}
}
templates add f("slice(indices: Iterable<Int>)") {
only(Lists, ArraysOfPrimitives, ArraysOfObjects)
doc { "Returns a list containing elements at specified positions" }
returns("List<T>")
body {
"""
val list = ArrayList<T>()
for (index in indices) {
list.add(get(index))
}
return list
"""
}
}
return templates
}