Skip to content

Commit 10463e1

Browse files
committed
Kotlin: Add List<T?>.requireNoNullsOrNull(): List<T>? utility
1 parent d4517f1 commit 10463e1

File tree

1 file changed

+13
-0
lines changed
  • java/kotlin-extractor/src/main/kotlin/utils

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.codeql
2+
3+
/**
4+
* Turns this list of nullable elements into a list of non-nullable
5+
* elements if they are all non-null, or returns null otherwise.
6+
*/
7+
public fun <T : Any> List<T?>.requireNoNullsOrNull(): List<T>? {
8+
try {
9+
return this.requireNoNulls()
10+
} catch (e: IllegalArgumentException) {
11+
return null;
12+
}
13+
}

0 commit comments

Comments
 (0)