Skip to content

Instantly share code, notes, and snippets.

View hoangchungk53qx1's full-sized avatar
๐Ÿ˜†
Out sick

hoangchung hoangchungk53qx1

๐Ÿ˜†
Out sick
View GitHub Profile
/*
* Copyright 2025 Kyriakos Georgiopoulos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
extension Publisher {
// The flatMapLatest operator behaves much like the standard FlatMap operator, except that whenever
// a new item is emitted by the source Publisher, it will unsubscribe to and stop mirroring the Publisher
// that was generated from the previously-emitted item, and begin only mirroring the current one.
func flatMapLatest<T: Publisher>(_ transform: @escaping (Self.Output) -> T) -> Publishers.SwitchToLatest<T, Publishers.Map<Self, T>> where T.Failure == Self.Failure {
map(transform).switchToLatest()
}
}
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Scheduler
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.kotlin.subscribeBy
import io.reactivex.rxjava3.schedulers.Schedulers
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
import kotlin.math.pow
import kotlin.random.Random