This file contains hidden or 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 android.os.AsyncTask | |
| interface Kind<F, A> | |
| class ForAsync private constructor() | |
| typealias Async<A> = Kind<ForAsync, A> | |
| fun <A> Async<A>.fix() = (this as TrueAsyncTask<A>) |
This file contains hidden or 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
| typealias Either7<A, B, C, D, E, F, G> = Either<A, Either<B, Either<C, Either<D, Either<E, Either<F, G>>>>>> | |
| typealias Either6<A, B, C, D, E, F> = Either7<A, B, C, D, E, F, Nothing> | |
| typealias Either5<A, B, C, D, E> = Either7<A, B, C, D, E, Nothing, Nothing> | |
| typealias Either4<A, B, C, D> = Either7<A, B, C, D, Nothing, Nothing, Nothing> | |
| typealias Either3<A, B, C> = Either7<A, B, C, Nothing, Nothing, Nothing, Nothing> | |
| fun <A, B, C, D, E, F, G, R> Either7<A, B, C, D, E, F, G>.fold( | |
| ifa: (A) -> R, | |
| ifb: (B) -> R, | |
| ifc: (C) -> R, |
This file contains hidden or 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
| fun main() { | |
| val res = caseOf("string", { | |
| case({ contains("s") }) { 1 } | |
| case({ contains("t") }) { 2 } | |
| }, orElse = { | |
| 3 | |
| }) | |
| } |
This file contains hidden or 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) { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |