inline fun <T, R> T.let(block: (T) -> R): R = block(this)
inline fun <T, R> T.run(block: T.() -> R): R = block()
| @Test | |
| fun simple() { | |
| val observable = Observable.create<Int> { emitter -> | |
| emitter.onNext(1) | |
| emitter.onError(IOException("Timeout")) | |
| } | |
| observable | |
| .take(1) | |
| .subscribe({ assertEquals(1, it) }, { assertTrue(it is UndeliverableException) }) | |
| } |
| override fun connectDevice(userDeviceRef: UserDeviceRef, deviceAttributes: DeviceAttributes, nodeRef: PilsnerRef): Completable | |
| = Completable.fromRunnable { | |
| rwLock.write { | |
| devicePresences[userDeviceRef.deviceId] = Presence(userDeviceRef, deviceAttributes, nodeRef) | |
| userDevices.put(userDeviceRef.userId, userDeviceRef.deviceId) | |
| } | |
| } | |
| override fun getPresencesOfUser(userId: UserId): Single<List<Presence>> | |
| = Single.fromCallable { |
| class Http { | |
| data class HeaderName(val name: String) : Comparable<HeaderName> { | |
| override fun compareTo(other: HeaderName): Int = name.compareTo(other.name, true) | |
| fun get(headers: MultiMap): String? = headers.get(name) | |
| fun set(headers: MultiMap, value: String): Unit { headers.set(name, value) } | |
| fun copyIfExist(from: MultiMap, to: MultiMap) { | |
| get(from)?.let { set(to, it) } | |
| } |
| @Test | |
| fun withLatestFromCausesNoSuchElementException() { | |
| val state = Observable.just(42).cacheWithInitialCapacity(1) | |
| var error = 0 | |
| val threads = (0..4 - 1) | |
| .map { | |
| Thread { | |
| Observable.just(Unit) | |
| .withLatestFrom(state, BiFunction { _: Unit, state: Int -> state }) | |
| .firstOrError() |
| /** | |
| * https://github.com/ultimate-deej/FlowLayout-for-Android/blob/master/src/org/deejdev/android/FlowLayout.java | |
| */ | |
| public class FlowLayout extends ViewGroup { | |
| public static final int LEFT_TO_RIGHT = 0; | |
| public static final int TOP_DOWN = 1; | |
| public static final int RIGHT_TO_LEFT = 2; | |
| public static final int BOTTOM_UP = 3; | |
| private int mGravity; |
| import rx.Observable | |
| interface RxPermission { | |
| val isGranted: Boolean | |
| fun request(): Observable<Boolean> | |
| } |
| class PingPongTest { | |
| fun containsDigit(n: Int, k: Int): Boolean = if (n == 0) false else if (n % 10 == k) true else containsDigit(n / 10, k) | |
| fun pingPong(n: Int) = Observable.range(1, n - 1) | |
| .map { it % 7 == 0 || containsDigit(it, 7) } | |
| .scan(1, { direction, turn -> direction * if (turn) -1 else 1 }) | |
| .scan { acc, direction -> acc + direction } | |
| .last() | |
| .toBlocking() | |
| .single() |
| import org.junit.Test | |
| import kotlin.test.assertTrue | |
| class TypeTest { | |
| operator fun Int.compareTo(other: String): Int { | |
| return 1 | |
| } | |
| @Test | |
| fun gt() { |
| class LocationAgreementAgree(scheduling: RxScheduling, | |
| api: Api, | |
| session: Session) : LocationAgreementSubmit(scheduling, api, session, true) { | |
| private val disuseChecked = BehaviorRelay.create<Boolean>(false) | |
| private val termsOfUseChecked = BehaviorRelay.create<Boolean>(false) | |
| private val ageChecked = BehaviorRelay.create<Boolean>(false) | |
| override val positiveEnabled = Observable.combineLatest(disuseChecked, termsOfUseChecked, ageChecked, { a, b, c -> a && b && c }) | |
| fun disuseChecked(): Observable<Boolean> = disuseChecked |