|
1 | 1 | package org.jetbrains.kotlinx.dataframe.api
|
2 | 2 |
|
| 3 | +import org.jetbrains.kotlinx.dataframe.DataColumn |
3 | 4 | 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 |
4 | 8 | import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
|
5 | 9 | import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
|
| 10 | +import org.jetbrains.kotlinx.dataframe.columns.values |
6 | 11 | import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnListImpl
|
7 | 12 |
|
| 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 | + |
8 | 46 | // region ColumnsSelectionDsl
|
9 | 47 |
|
10 | 48 | /**
|
|
0 commit comments