Add mapNonNullIndexed API to List and Set (#1063)

This commit is contained in:
Josh B
2025-05-08 06:57:28 -07:00
committed by GitHub
parent 919d63e51a
commit 948a20ad0c
7 changed files with 78 additions and 6 deletions
@@ -332,6 +332,11 @@ examples {
List(1, 2, 3).mapIndexed((i, n) -> i.isOdd && n.isEven)
}
["mapNonNullIndexed()"] {
List(1, 2, 3, 4).mapNonNullIndexed((i, n) -> if (n.isOdd) null else n * i)
List(1, 2, 3, 4, null).mapNonNullIndexed((i, n) -> if (n?.isOdd ?? true) null else n * i)
}
["flatMapIndexed()"] {
List(1, 2, 3).flatMapIndexed((i, n) -> List(n * i))
List(1, 2, 3).flatMapIndexed((i, n) -> List(i.isOdd && n.isEven))
@@ -280,6 +280,11 @@ examples {
Set(1, 2, 3, 3, 2, 1).mapIndexed((i, n) -> i.isOdd && n.isEven)
}
["mapNonNullIndexed()"] {
Set(1, 2, 3, 4, 4, 3, 2, 1).mapNonNullIndexed((i, n) -> if (n.isOdd) null else n * i)
Set(1, 2, 3, 4, null, 4, 3, 2, 1).mapNonNullIndexed((i, n) -> if (n?.isOdd ?? true) null else n * i)
}
["flatMapIndexed()"] {
Set(1, 2, 3, 3, 2, 1).flatMapIndexed((i, n) -> Set(n * i))
Set(1, 2, 3, 3, 2, 1).flatMapIndexed((i, n) -> Set(i.isOdd && n.isEven))
@@ -274,6 +274,10 @@ examples {
List(0, 2, 6)
List(false, true, false)
}
["mapNonNullIndexed()"] {
List(2, 12)
List(2, 12)
}
["flatMapIndexed()"] {
List(0, 2, 6)
List(false, true, false)
@@ -227,6 +227,10 @@ examples {
Set(0, 2, 6)
Set(false, true)
}
["mapNonNullIndexed()"] {
Set(2, 12)
Set(2, 12)
}
["flatMapIndexed()"] {
Set(0, 2, 6)
Set(false, true)