This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kondenko.pocketwaka.utils | |
import io.reactivex.Observable | |
import io.reactivex.ObservableOperator | |
import io.reactivex.Observer | |
import io.reactivex.disposables.Disposable | |
fun <T, R> Observable<T>.scanMap(initialValue: T? = null, scanMap: (T, T) -> R): Observable<R> = | |
lift(ScanMap(initialValue, scanMap)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DiffUtilDelegate<T, VH : RecyclerView.ViewHolder, A : RecyclerView.Adapter<VH>>( | |
initialValue: List<T>, | |
private val callbackFactory: (List<T>, List<T>) -> DiffUtil.Callback = | |
{ old, new -> SimpleCallback(old, new) } | |
) { | |
private var currentValue: List<T> = initialValue | |
operator fun setValue(thisRef: A?, property: KProperty<*>, value: List<T>) { | |
val callback = callbackFactory(currentValue, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalCoroutinesApi | |
fun <T> Flow<T>.bufferList(capacity: Int): Flow<List<T>> { | |
require(capacity > 0) { "Buffer size should be positive, but was $capacity" } | |
var buffer = listOf<T>() | |
return transform { value -> | |
if (buffer.size == capacity) emit(buffer) | |
else buffer = buffer + value | |
} | |
} |