Items

interface Items<out T>

Items 是一个数据预处理序列,类似于 java.util.stream.Streamkotlinx.coroutines.flow.Flow, 但是不完全相同。

在使用 items 的预处理参数时,你不应去重复使用已经被操作过的过时实例。

预处理

Items 中存在部分 预处理 函数:limitoffsetbatch

这些预处理函数的作用可能是单纯的记录参数,如果重复调用会覆盖上一个值而不是真正的流式处理。因此对于这些预处理函数, 如果有需要则应当只调用一次。

这些预处理函数不同于其他流API中的类似api,在simbot中,组件的实现可能会根据这些预处理参数进行一定的优化。 当一个组件底层的api原生的支持精准的分页、分流时,这些参数便会派上用场了。同理,如果底层api无法直接获取全部, 需要分批次获取的时候,batch 则会有效影响到实际的批次数量 ———— 这些都是普通的流API无法满足的。

为了避免实现细节所产生的逻辑差异,对于 预处理 函数,同一个函数你应当至多只调用1次。

转化

Items 中存在部分 转化 函数:asFlowasSequenceasStream

转化 函数是一种 终结 函数,它会将当前预处理信息的瞬时信息提供给内部的构建器,并得到一个真正的序列对象。

收集

Items 中存在部分 收集 函数:Items.collectToItems.collectToList 等。

收集 函数是一种 终结 函数,它会将当前预处理信息的瞬时信息提供给内部的构建器,并进行真正的处理逻辑。

与上述 转化 函数类似,收集函数被执行时才会根据预处理参数去真正的构建流实例并进行收集操作。 因此在调用了 收集 函数后,你不应再对之前的 Items 实例进行任何操作。


不论是转化函数还是收集函数,它们都是终结函数,每一个 Items 应当且只能执行一次终结函数,不可复用

Author

ForteScarlet

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Items 中通过预处理函数所配置的预处理值。 如果值为 -1 则代表未配置。

Functions

Link copied to clipboard
abstract fun asFlow(): Flow<T>

将当前元素序列转化为 Flow.

Link copied to clipboard
abstract fun asSequence(): Sequence<T>

将当前元素序列转化为 Sequence.

Link copied to clipboard
abstract fun asStream(): Stream<out T>

将当前元素序列转化为 Stream.

Link copied to clipboard
abstract fun batch(size: Int): Items<T>

批次大小。如果支持批次获取的话,则每批次获取 size 的元素数量。通常 size 0 时有效。

Link copied to clipboard
open fun collect(collector: Consumer<in T>)

阻塞地收集当前序列中的元素。

abstract suspend fun collect(collector: suspend (T) -> Unit)

收集当前数据序列中的元素. collectTo 可能会产生挂起,会直到当前序列中的所有可能产生的元素收集完毕后结束挂起。

Link copied to clipboard
open fun collectAsync(collector: Consumer<in T>): CompletableFuture<Unit>

异步地收集当前序列中的元素。

Link copied to clipboard
open fun <C : MutableCollection<in T>> collectTo(collector: C): C

阻塞地收集当前序列中的元素到目标 collector 中。

Link copied to clipboard
open fun <C : MutableCollection<in T>> collectToAsync(collector: C): CompletableFuture<out C>

异步的将内容元素收集到 collector 中。

Link copied to clipboard
open fun collectToList(): List<T>

阻塞的收集当前序列中的元素到列表中。

Link copied to clipboard

异步收集当前序列中的元素到列表中。

Link copied to clipboard
abstract fun limit(count: Int): Items<T>

数据限流。取得的数据条数的最大上限。当 count 0 时有效。

Link copied to clipboard
abstract fun offset(count: Int): Items<T>

数据偏移。从 offset 数量之后的数据后开始获取。当 offset 0 时有效。

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
inline fun <B, T> Items<B>.map(crossinline transform: suspend (B) -> T): Items<T>

转化一个 Items 中的元素类型并得到新的 Items 实例。

Link copied to clipboard
inline suspend fun <T, C : MutableCollection<T>> Items<T>.toCollection(collection: C): C

Items 中的元素收集为目标集合 C.

Link copied to clipboard
inline suspend fun <T> Items<T>.toList(): List<T>

Items 中的元素收集为 List.

Link copied to clipboard
fun <B, T> Items<B>.transform(transform: suspend (B) -> T): Items<T>

转化一个 Items 中的元素类型并得到新的 Items 实例。

Link copied to clipboard
@JvmName(name = "transform")
fun <B, T> Items<B>.transformBlocking(transform: (B) -> T): Items<T>

转化一个 Items 中的元素类型并得到新的 Items 实例。

Link copied to clipboard
fun <T> Items<T>.withLimiter(limiter: Limiter): Items<T>

通过 LimiterItems 的预处理参数进行处理。