mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 01:29:15 +02:00
Add mapNonNullIndexed API to List and Set (#1063)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user