Kotlin: Add List<T?>.requireNoNullsOrNull(): List<T>? utility

This commit is contained in:
Ian Lynagh
2022-08-15 14:38:09 +01:00
parent d4517f1266
commit 10463e12a7

View 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;
}
}