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 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 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
| Single.just(3).map { x -> x.toString() } |
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
| 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() |
NewerOlder