Daniel
05/24/2017, 8:42 AMfun <T> ArrayList<T>.transformAll(transform: (T) -> T) {
for(i in firstIndex..lastIndex) {
this[i] = transform(this[i])
}
}
@Test
fun `Should apply the transformation to each element of the array list`() {
// GIVEN
val list = arrayListOf(2, 3, 4)
// WHEN
list.transformAll { it * 2 }
// THEN
assertThat(list, `is`(equalTo(arrayListOf(4, 6, 8))))
}
oranj
05/24/2017, 9:12 AMAndreas Sinz
05/24/2017, 9:27 AMis
is a reserved keywordDaniel
05/24/2017, 9:27 AMis
is a keyword in Kotlin (the equivalent to instanceOf) so normally you coulndn't use it as a function name. The backticks tell the compiler that is
is not a keyword in this contextoranj
05/24/2017, 9:27 AMDaniel
05/24/2017, 9:30 AM