These are chat archives for ReactiveX/RxJava

21st
Jun 2018
sphrak
@sphrak
Jun 21 2018 17:37

Hello,
I have this test code:

    @Test
    fun delete_file_not_found() {
        fileRepository.delete(File("non_existent_example_file.jpg"))
                .test()
                .assertValue{
                    t: Result<String> -> t == Result.failure(Error.FileNotFoundError(R.string.file_not_found.toString()))
                }
    }

but it produces java.lang.AssertionError: Value not present (latch = 0, values = 1, errors = 0, completions = 1) -- what am I doing wrong and is it even something im doing wrong with RxJava? sorry but im new to this

Matthew Adams
@matthewadams
Jun 21 2018 18:11
How do I convert an Observable<Single<T>> to an Observable<T> in RxJava 1.x? Example:
public Single<Document> getDocument(String id) {
  return Single.just(new Document());
}
public Observable<Document> getDocuments(String... ids) {
  return Observable.from(ids).map(id -> getDocument(id))...???
}
lukaszguz
@lukaszguz
Jun 21 2018 19:02
Hi @matthewadams,
you can do it like that:
public Observable<Document> getDocuments(String... ids) { return Observable.from(ids).map(this::getDocument) .flatMap(Single::toObservable); }
David Karnok
@akarnokd
Jun 21 2018 19:02
@sphrak is == reference equals in Kotlin? If so, t won't be reference equal to that value. Try equals.
Matthew Adams
@matthewadams
Jun 21 2018 19:02
yes, thanks @lukaszguz . Arrived at that solution literally 2 mins ago. :)
lukaszguz
@lukaszguz
Jun 21 2018 19:03
:)
Matthew Adams
@matthewadams
Jun 21 2018 19:05
@lukaszguz this was my code: Observable.concat(Observable.from(ids).map(id -> getDocument(id).toObservable()));
I think I like yours better :)
lukaszguz
@lukaszguz
Jun 21 2018 19:10
I'm glad I could help :D
sphrak
@sphrak
Jun 21 2018 19:14
@akarnokd thanks for you input, the way I understood it, == in kotlin would allow for checking if two objects are of the same type say, but not necessary the same instance of said object. I tried equals but I still get that Value not present error.
sphrak
@sphrak
Jun 21 2018 19:22
In kotlin == is called structural equality, referential equality is done by ===.. so == is what I want I think, I do not want to know if they point to same place in memory..
David Karnok
@akarnokd
Jun 21 2018 20:25
In that case, place a breakpoint in the body and see what t is in the variable window.
sphrak
@sphrak
Jun 21 2018 20:50
@akarnokd I'm sorry but it turns out I am an idiot. The error class was suppose to be a kotlin data class.. however looking closer it wasnt, so there where no equals method implemented.. thus the == failed, so it works now :)