#KT-2341 Fixed
This commit is contained in:
committed by
Alexander Udalov
parent
e179e6bb2f
commit
6546d7a1e7
@@ -90,7 +90,7 @@ val <T> List<T>.lastIndex : Int
|
||||
* @includeFunctionBody ../../test/ListTest.kt head
|
||||
*/
|
||||
val <T> List<T>.head : T?
|
||||
get() = this.get(0)
|
||||
get() = if (this.isNotEmpty()) this.get(0) else null
|
||||
|
||||
/**
|
||||
* Returns all elements in this collection apart from the first one
|
||||
|
||||
@@ -11,6 +11,11 @@ class ListTest {
|
||||
assertEquals("[foo, bar]", data.toString())
|
||||
}
|
||||
|
||||
test fun emptyHead() {
|
||||
val data = ArrayList<String>()
|
||||
assertNull(data.head)
|
||||
}
|
||||
|
||||
test fun head() {
|
||||
val data = arrayList("foo", "bar")
|
||||
assertEquals("foo", data.head)
|
||||
@@ -23,6 +28,11 @@ class ListTest {
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
test fun emptyFirst() {
|
||||
val data = ArrayList<String>()
|
||||
assertNull(data.first)
|
||||
}
|
||||
|
||||
test fun first() {
|
||||
val data = arrayList("foo", "bar")
|
||||
assertEquals("foo", data.first)
|
||||
|
||||
Reference in New Issue
Block a user