Generate indexOf and lastIndexOf extensions for List.

This commit is contained in:
Ilya Gorbunov
2015-11-26 06:05:52 +03:00
parent c7d08ea599
commit de86e90103
3 changed files with 42 additions and 29 deletions
@@ -271,6 +271,13 @@ public fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.indexOf(element: T):
return -1
}
/**
* Returns first index of [element], or -1 if the list does not contain element.
*/
public fun <@kotlin.internal.OnlyInputTypes T> List<T>.indexOf(element: T): Int {
return indexOf(element)
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
@@ -282,6 +289,17 @@ public fun <T> Iterable<T>.indexOf(element: T): Int {
return indexOf(element as Any?)
}
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("List and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as Any?)"))
@kotlin.jvm.JvmName("indexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> List<T>.indexOf(element: T): Int {
return indexOf(element as Any?)
}
/**
* Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
*/
@@ -433,6 +451,13 @@ public fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.lastIndexOf(element:
return lastIndex
}
/**
* Returns last index of [element], or -1 if the list does not contain element.
*/
public fun <@kotlin.internal.OnlyInputTypes T> List<T>.lastIndexOf(element: T): Int {
return lastIndexOf(element)
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
@@ -444,6 +469,17 @@ public fun <T> Iterable<T>.lastIndexOf(element: T): Int {
return lastIndexOf(element as Any?)
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
@Deprecated("List and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as Any?)"))
@kotlin.jvm.JvmName("lastIndexOfAny")
@kotlin.internal.LowPriorityInOverloadResolution
@Suppress("NOTHING_TO_INLINE")
public fun <T> List<T>.lastIndexOf(element: T): Int {
return lastIndexOf(element as Any?)
}
/**
* Returns last index of [element], or -1 if the collection does not contain element.
* Allows to overcome type-safety restriction of `lastIndexOf` that requires to pass an element of type `T`.