mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Kotlin: Add List<T?>.requireNoNullsOrNull(): List<T>? utility
This commit is contained in:
13
java/kotlin-extractor/src/main/kotlin/utils/List.kt
Normal file
13
java/kotlin-extractor/src/main/kotlin/utils/List.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.github.codeql
|
||||
|
||||
/**
|
||||
* Turns this list of nullable elements into a list of non-nullable
|
||||
* elements if they are all non-null, or returns null otherwise.
|
||||
*/
|
||||
public fun <T : Any> List<T?>.requireNoNullsOrNull(): List<T>? {
|
||||
try {
|
||||
return this.requireNoNulls()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user