This library provides basic transformation functions for your LiveData
objects.
map
switchMap
switchLatest
filter
filterNotNull
distinct
distinctUntilChanged
merge
combineLatest
startWith
first
take
takeUntil
takeWhile
buffer
cast
- and more...
val source: LiveData<Int> = // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
source.filter { it % 2 == 1 }.observe(this) {
println(it) // 1, 3, 5, 7, 9
}
val source: LiveData<Int> = // 1, 2, 1, 3, 2, 4, 1, 3, 2, 5
source.distinct().observe(this) {
println(it) // 1, 2, 3, 4, 5
}
val source1: LiveData<String> = // 1, 2, 3,
val source2: LiveData<Int> = // a, b, c,
listOf(source1, source2).merge().observe(this) { value ->
println(value) // a, 1, b, 2, c, 3
}
repositories {
mavenCentral()
}
dependencies {
implementation 'de.musichin.reactivelivedata:reactivelivedata:x.y.z'
}
Contributors are more than welcome. Just upload a PR with a description of your changes.
File github issues for anything that is unexpectedly broken.
MIT License
Copyright (c) 2017 Anton Musichin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.