pushtorefresh / storio

Reactive API for SQLiteDatabase and ContentResolver.
Apache License 2.0
2.54k stars 182 forks source link

Support io.reactivex.Maybe #846

Closed geralt-encore closed 6 years ago

geralt-encore commented 7 years ago

I'll work on this as soon as initial RxJava 2 support will be merged

nikitin-da commented 7 years ago

It will be great!

geralt-encore commented 6 years ago

I've started to look into Maybe implementation and not everything is quite clear.
To be able to properly implement MaybeOnSubscribeExecuteAsBlocking there has to be a way to distinguish between empty and non-empty cases. Since Result is generic the only way to achieve it is to make executeAsBlocking nullable again. Is it ok or am I missing something?

geralt-encore commented 6 years ago

Another question. What will be correct for empty list/cursor cases: to return an empty list/cursor or to just complete stream without an emission?

nikitin-da commented 6 years ago

Dumn, my bad=( preparedOperation's Result must be must be Optional and unwrapperd nullable value at the same time =(

Maybe we should create separate WrappedResult generic type, that will duplicate Result for listOfObject and cursor?

Otherwise, if we are ok that result of Maybe is Optional than we can create separate MaybeOnSubscribeExecuteAsBlocking implementations for Optional<T>, List<T> and so on.

//cc @artem-zinnatullin

What will be correct for empty list/cursor cases: to return an empty list/cursor or to just complete stream without an emission?

I guess we should complete stream without an emission, otherwise it will be the same asRxSingle

geralt-encore commented 6 years ago

I guess we should complete stream without an emission, otherwise it will be the same asRxSingle

Had the same thoughts and just wanted to verify it.

Not sure if I got what you were saying about preparedOperation's Result. Isn't actual wrapping happens on Interceptor level so we can return null for Maybe case and still be able to use Optional for Single?

nikitin-da commented 6 years ago

Not quite so, interceptor must return value of the same type as prepared operation uses So all other methods (executeAsBlocking, asRxFlowable) must return values with the same type =(

geralt-encore commented 6 years ago

Yeah, now I see... Have to think more about it then

nikitin-da commented 6 years ago

As I said before maybe we can add WrappedResult type in prepared operation declaration executeAsBlocking, asRxMaybe and interceptors will continue to work with Result, nut asRxSingle and asRxFlowable will return WrappedResult. That will be Optional only for PreparedGet. So SingleOnSubscribeExecuteAsBlocking and FlowableOnSubscribeExecuteAsBlocking will be responsible for optional creation

geralt-encore commented 6 years ago

I'll look into it tomorrow with a clear head =)

nikitin-da commented 6 years ago

I will prepare some draft for this idea in 2 hours

nikitin-da commented 6 years ago

I suppose something like this