-
Notifications
You must be signed in to change notification settings - Fork 455
rxKotlin for rxJava2 #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Awesome! I'll take a look later... |
|
@thomasnield thanks a lot |
LICENSE
Outdated
| To apply the Apache License to your work, attach the following | ||
| boilerplate notice, with the fields enclosed by brackets "[]" | ||
| replaced with your own identifying information. (Don't include | ||
| replaced with your own identifying information. (Don'value include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep Don't
build.gradle
Outdated
|
|
||
| task wrapper(type: Wrapper) { | ||
| gradleVersion = '2.2.1' | ||
| gradleVersion = '2.10' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance for nebula to work with gradle 3+?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In RxAndroid we dropped nebula. It hurts more than it helps.
| subscriber.onNext("Hello") | ||
| subscriber.onCompleted() | ||
| }).subscribe { result -> | ||
| Observable.create<kotlin.String> { onSubscribe -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kotlin.String -> String
build.gradle
Outdated
|
|
||
| task wrapper(type: Wrapper) { | ||
| gradleVersion = '2.2.1' | ||
| gradleVersion = '2.10' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In RxAndroid we dropped nebula. It hurts more than it helps.
| println("--- Error ---\n${e.message}") | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with all the added trailing whitespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like default kotlin formatting settings in one of the last plugin releases.
| fun asyncWiki(vararg articleNames: String): Observable<String> = observable { subscriber -> | ||
| thread { | ||
| articleNames.toObservable() | ||
| .flatMapMaybe { name: String -> URL("http://en.wikipedia.org/wiki/$name").toScannerObservable().firstElement() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the argument need an explicit type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope
| /** | ||
| * [Observable.defer] alias | ||
| */ | ||
| fun <T : Any> Observable<T>.defer() = Observable.defer { this } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't exist. The whole point of defer is the function is deferred to create an Observable. If you already have one there's no point in calling defer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, forgot to delete it before commit
|
|
||
| @Suppress("BASE_WITH_NULLABLE_UPPER_BOUND") fun <T> Observable<T>.onErrorReturnNull() : Observable<T?> = onErrorReturn<T> {null} | ||
| fun <T : Any> T.toSingletonObservable(): Observable<T> = Observable.just(this) | ||
| fun <T : Any> Throwable.toObservable(): Observable<T> = Observable.error(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two are a bit ridiculous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
Code review related fixes.
| import io.reactivex.disposables.Disposable | ||
| import java.util.ArrayList | ||
|
|
||
| class FunctionSubscriber<T : Any> : Observer<T>, MaybeObserver<T>, SingleObserver<T>, CompletableObserver { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reimplement using OnSubscribe* interfaces
| } | ||
|
|
||
| private fun URL.toScannerObservable() = observable<String> { s -> | ||
| private fun URL.toScannerObservable() = observable<String>({ s -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove ()
|
Porting |
|
I was thinking about that for a few days. Makes sense but it's too bad. Is there a way to present each action as a named parameter to |
import io.reactivex.Observable
fun main(args: Array<String>) {
Observable.just("Alpha", "Beta", "Gamma")
.subscribe(onNext = ::println, onComplete = { println("done") })
}
fun <T> Observable<T>.subscribe(onNext: ((T) -> Unit)? = null,
onError: ((Throwable) -> Unit)? = null,
onComplete: (() -> Unit)? = null) = subscribe(onNext, onError, onComplete)
|
|
@thomasnield that's exactly what I'm thinking about. The only problem is - the name of a function, ide will not auto-import it because of the name clash. |
|
RxJava2 don't accept null params in |
|
RxJava2 doesn't accept null anything it seems. I guess you can just create a hard observer in the implementation then... |
flowable extensions added minor fixes
|
@stepango According to https://kotlinlang.org/docs/reference/packages.html, you can use alias for name clash such as like "import bar.Bar as bBar // bBar stands for 'bar.Bar'" |
|
@iNoles I know about import aliases, do you have some particular use case in mind? |
|
@stepango I was thinking about to use rxjava as import alias. |
|
@iNoles don't get it. What exactly do you mean? Any code examples? |
|
@stepango is it possible you can merge what you have into 2.x? I'd like to start contributing to this and it might be easier to centralize it into the repository. |
|
@thomasnield was just about to do that. Finally, have some free time this weekend. |
Start working on rxKotlin for rxJava2. For now, it's just a raw port of rxKotlin. Any feedback highly appreciated.