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
object Sentries { | |
private val callbacks = ConcurrentHashMap<Reference<*>, () -> Unit>() | |
private val refs = HashSet<WeakReference<*>>() | |
private val refQueue = ReferenceQueue<Sentry<*>>() | |
private val poller = | |
Observable.interval(10000, TimeUnit.MILLISECONDS) | |
.subscribe { | |
refQueue.poll()?.let { ref -> | |
callbacks.remove(ref)?.invoke() |
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
Single.just(3).map { x -> x.toString() } |
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 SetBackedMap<K, V>(private val set: Set<Map.Entry<K, V>>) : Map<K, V> { | |
override val entries: Set<Map.Entry<K, V>> = set | |
override val keys: Set<K> = set.map { (key, _) -> key }.toSet() | |
override val size: Int = set.size | |
override val values: Collection<V> = set.map { (_, value) -> value } | |
override fun containsKey(key: K): Boolean { | |
return set.any { (possibleKey, _) -> possibleKey == key } | |
} |
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
sealed class DiffOp { | |
data class Insert(val oldPos: Int, val newPos: Int) : DiffOp() | |
data class Delete(val oldPos: Int) : DiffOp() | |
} | |
fun <T> diff(list1: MutableList<T>, list2: MutableList<T>, i: Int = 0, j: Int = 0): List<DiffOp> { | |
val N = list1.size |
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
import kotlin.coroutines.* | |
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED | |
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn | |
class NullableComprehension<R> : Continuation<R> { | |
override val context: CoroutineContext = EmptyCoroutineContext | |
private var internalResult: R? = null |
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 JEither<L, R> { | |
private L left; | |
private R right; | |
private JEither() {} | |
public <C> C fold(Function<L, C> ifLeft, Function<R, C> ifRight) { | |
if (left != null) { | |
return ifLeft.apply(left); |
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 BetterWhen<T, R>(val appl: T) { | |
var result: R? = null | |
fun cond(p: (T) -> Boolean, res: () -> R) { | |
if (p(appl)) { | |
result = res() | |
throw Interrupt() |
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
Kto prochital, tot gey))0) |
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
import io.reactivex.Single | |
import io.reactivex.functions.BiFunction | |
interface Kind<out C, out A> | |
class ForSingle private constructor() | |
class SingleContainer<T>(val single: Single<T>): Kind<ForSingle, T> | |
fun <T> Kind<ForSingle, T>.fix() = (this as SingleContainer<T>).single | |
fun <T> Single<T>.unfix() = SingleContainer(this) |
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
typedef Function1<A, R> = R Function(A param); | |
class Either<L, R> { | |
bool _isRight; | |
L _left; | |
R _right; | |
C fold<C>(Function1<L, C> ifLeft, Function1<R, C> ifRight) { | |
if (_isRight) { |
OlderNewer