Skip to content
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

add original operator #1

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/io/reactivex/Flowable.java
Expand Up @@ -2491,6 +2491,13 @@ public static <T> Flowable<T> just(T item) {
return RxJavaPlugins.onAssembly(new FlowableJust<T>(item));
}

@CheckReturnValue
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public static Flowable<String> imo() {
return RxJavaPlugins.onAssembly(new FlowableImo());
}

/**
* Converts two items into a Publisher that emits those items.
* <p>
Expand Down Expand Up @@ -12340,6 +12347,13 @@ public final Flowable<T> skip(long count) {
return RxJavaPlugins.onAssembly(new FlowableSkip<T>(this, count));
}

@CheckReturnValue
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> println() {
return RxJavaPlugins.onAssembly(new FlowablePrintln<T>(this));
}

/**
* Returns a Flowable that skips values emitted by the source Publisher before a specified time window
* elapses.
Expand Down
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.internal.operators.flowable;

import io.reactivex.Flowable;
import io.reactivex.internal.fuseable.ScalarCallable;
import io.reactivex.internal.subscriptions.ScalarSubscription;
import org.reactivestreams.Subscriber;

/**
* Represents a constant `imo`.
*/
public final class FlowableImo extends Flowable<String> {
public FlowableImo() {
}

@Override
protected void subscribeActual(Subscriber<? super String> s) {
s.onSubscribe(new ScalarSubscription<String>(s, "imo"));
}
}
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.internal.operators.flowable;

import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

public final class FlowablePrintln<T> extends AbstractFlowableWithUpstream<T, T> {
public FlowablePrintln(Flowable<T> source) {
super(source);
}

@Override
protected void subscribeActual(Subscriber<? super T> s) {
source.subscribe(new PrintlnSubscriber<T>(s));
}

static final class PrintlnSubscriber<T> implements FlowableSubscriber<T>, Subscription {
final Subscriber<? super T> actual;

Subscription s;

PrintlnSubscriber(Subscriber<? super T> actual) {
this.actual = actual;
}

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.validate(this.s, s)) {
this.s = s;
actual.onSubscribe(this);
}
}

@Override
public void onNext(T t) {
System.out.println(t);
actual.onNext(t);
}

@Override
public void onError(Throwable t) {
actual.onError(t);
}

@Override
public void onComplete() {
actual.onComplete();
}

@Override
public void request(long n) {
s.request(n);
}

@Override
public void cancel() {
s.cancel();
}
}
}