Skip to content

Instantly share code, notes, and snippets.


Vladimir Kondenko

View GitHub Profile
View ScanMap
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))
Kondenko / DiffUtilDelegate.kt
Last active Jun 24, 2019
A delegate to update RecycletView's adapter data with DiffUtil
View DiffUtilDelegate.kt
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)
Kondenko / FlowExtensions.kt
Created Jun 15, 2019
Kotlin Flow Extensions
View FlowExtensions.kt
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
You can’t perform that action at this time.