1

I have some methods

Maybe<Foo> getLocalFoo()
Single<List<Foo>> getFooFromInternet()

And want to check local item and if it's empty then fetch that item from network for example.

storage
            .getLocalFoo()
            .switchIfEmpty { network.getFooFromInternet().map { it[0] }.toMaybe() }
            .subscribe({}, {})

But seens that code doesn't execute network.getBarcodeTemplates() this function.

Sunstrike
  • 456
  • 1
  • 6
  • 22

1 Answers1

3

Try with ( instead of { in the switchIfEmpty line:

.switchIfEmpty ( network.getFooFromInternet().map { it[0] }.toMaybe() )
akarnokd
  • 69,132
  • 14
  • 157
  • 192
  • Yep, that was the problem. Thank you. And maybe if you will have free time you can check my new problem with andThen https://stackoverflow.com/questions/45834989/andthen-executes-before-completable-finished – Sunstrike Aug 23 '17 at 08:54