Skip to content

Instantly share code, notes, and snippets.

@arkivanov
Last active May 10, 2019 16:13
Show Gist options
  • Save arkivanov/e1ad0b6f1a63957ed18312ec788f6cb0 to your computer and use it in GitHub Desktop.
Save arkivanov/e1ad0b6f1a63957ed18312ec788f6cb0 to your computer and use it in GitHub Desktop.
Reaktive null-safety exmaples
// 1
observableOf<String>(null) // Compilation error
// 2
val o1: Observable<String?> = observableOf(null)
val o2: Observable<String> = o1 // Compilation error, types do not match
// 3
val o1: Observable<String?> = observableOf(null)
val o2: Observable<String> = o1.notNull() // No error, null values filtered out
// 4
val o1: Observable<String> = observableOf(“Hello”)
val o2: Observable<String?> = o1 // No error
// 5
val o1: Observable<String?> = observableOf(null)
val o2: Observable<String> = observableOf(“Hello”)
val o3: Observable<String?> = merge(o1, o2) // No error
val o4: Observable<String> = merge(o1, o2) // Compilation error, types do not match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment