Skip to content

Instantly share code, notes, and snippets.

@maxost
maxost / SmsReceiver.kt
Created September 5, 2017 02:40
Kotlin: sms receiver and rx bus in Android
data class Sms(val phone: String, val text: String)
object SmsBus {
private val bus by lazy { PublishSubject.create<Sms>() }
fun incomingSms(): Observable<Sms> = bus
fun postSms(sms: Sms) = bus.onNext(sms)
}
@maxost
maxost / Option.kt
Created September 5, 2017 02:41
Kotlin: simple Option implementation
sealed class Option<out A> {
abstract fun get(): A
object None : Option<Nothing>() {
override fun get(): Nothing = throw NoSuchElementException("None.get")
}
data class Some<out A>(val value: A) : Option<A>() {
override fun get(): A = value