Skip to content

Commit bef0c40

Browse files
Automated commit of generated code
1 parent 56b76f4 commit bef0c40

File tree

2 files changed

+51
-0
lines changed
  • core/generated-sources/src

2 files changed

+51
-0
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/none.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

3+
import org.jetbrains.kotlinx.dataframe.DataColumn
34
import org.jetbrains.kotlinx.dataframe.DataFrame
5+
import org.jetbrains.kotlinx.dataframe.DataRow
6+
import org.jetbrains.kotlinx.dataframe.Predicate
7+
import org.jetbrains.kotlinx.dataframe.RowFilter
48
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
59
import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
10+
import org.jetbrains.kotlinx.dataframe.columns.values
611
import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnListImpl
712

13+
// region DataColumn
14+
15+
/** Returns `true` if none of the [values] match the given [predicate] */
16+
public fun <T> DataColumn<T>.none(predicate: Predicate<T>): Boolean = values.none(predicate)
17+
18+
// endregion
19+
20+
// region DataFrame
21+
22+
/**
23+
* Returns `true` if none of the rows in this [DataFrame] satisfies the given [predicate].
24+
*
25+
* The [predicate] is a [RowFilter][org.jetbrains.kotlinx.dataframe.RowFilter] — a lambda that receives each [DataRow][org.jetbrains.kotlinx.dataframe.DataRow] as both `this` and `it`
26+
* and is expected to return a [Boolean] value.
27+
*
28+
* It allows you to define conditions using the row's values directly,
29+
* including through [extension properties][org.jetbrains.kotlinx.dataframe.documentation.ExtensionPropertiesAPIDocs] for convenient and type-safe access.
30+
*
31+
* ### Example
32+
* ```kotlin
33+
* // Check if there is not any row where "age" is greater than 18
34+
* val hasNoAdults = df.none { age > 18 }
35+
* ```
36+
*
37+
* @param predicate A [RowFilter] lambda that takes a [DataRow] (as both `this` and `it`)
38+
* and returns `true` if none of the rows should be considered a match.
39+
* @return `true` if none of the rows satisfies the [predicate], `false` otherwise.
40+
* @see [DataFrame.any]
41+
*/
42+
public inline fun <T> DataFrame<T>.none(predicate: RowFilter<T>): Boolean = rows().none { predicate(it, it) }
43+
44+
// endregion
45+
846
// region ColumnsSelectionDsl
947

1048
/**

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/UtilFunctionsTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,25 @@ class UtilFunctionsTest : TestBase() {
1818
ageCol.any { it > 90 } shouldBe false
1919
}
2020

21+
@Test
22+
fun `DataColumn none`() {
23+
val ageCol = df["age"] as DataColumn<Int>
24+
ageCol.none { it > 40 } shouldBe false
25+
ageCol.none { it > 90 } shouldBe true
26+
}
27+
2128
@Test
2229
fun `DataFrame any`() {
2330
df.any { "age"<Int>() > 40 && "isHappy"<Boolean>() } shouldBe true
2431
df.any { "city"<String?>() == "Berlin" } shouldBe false
2532
}
2633

34+
@Test
35+
fun `DataFrame none`() {
36+
df.none { "age"<Int>() > 40 && "isHappy"<Boolean>() } shouldBe false
37+
df.none { "city"<String?>() == "Berlin" } shouldBe true
38+
}
39+
2740
@Test
2841
fun `DataColumn between`() {
2942
val ages = listOf(15, 45, 20, 40, 30, 20, 30)

0 commit comments

Comments
 (0)