liminal
liminal

Reputation: 1164

RxJava stream transformation

I have the following functions declared in the repo:

fun loadAllNotifications(): Single<List<Notification>>

fun insertAll(notifications: List<Notification>): Completable

What I'd like to do is to loadAllNotifications() and then for each Notification reset its isOpened flag to false by doing something like

val updatedNotification = currentNotification.copy(isOpened = false)

Once I have a list of Notifications with the isOpened set to false, I'd like to pass this list into insertAll(list)

How would I do the above in a single RxChain? Any help will be greatly appreciated.

Upvotes: 0

Views: 39

Answers (1)

ConstOrVar
ConstOrVar

Reputation: 2085

loadAllNotifications()
        .flatMapObservable { Observable.fromIterable(it) }
        .map { it.copy(isOpened = false) }
        .toList()
        .flatMapCompletable{ insertAll(it) }

Upvotes: 1

Related Questions