[PM-22786] Migrate PersistentListExtensions to core module (#5380)

This commit is contained in:
Patrick Honkonen
2025-06-18 14:42:54 -04:00
committed by GitHub
parent 08b07a0050
commit 56e8acf81f
12 changed files with 12 additions and 11 deletions

View File

@@ -0,0 +1,10 @@
package com.bitwarden.core.util
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
/**
* Creates an immutable [ImmutableList] of the given [elements] excluding the null ones.
*/
fun <T : Any> persistentListOfNotNull(vararg elements: T?): ImmutableList<T> =
elements.filterNotNull().toImmutableList()

View File

@@ -0,0 +1,23 @@
package com.bitwarden.core.util
import kotlinx.collections.immutable.persistentListOf
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class PersistentListExtensionsTest {
@Test
fun `PersistentListOfNotNull should filter out null values`() {
val expected = persistentListOf("Hello", "World")
val result = persistentListOfNotNull(
"Hello",
null,
"World",
null,
null,
)
assertEquals(expected, result)
}
}