Skip to content

Commit ed66751

Browse files
Merge branch 'OperatorComputationExpr' of github.com:akarnokd/RxJava into merge-prs
2 parents fa13aa5 + 6fe11aa commit ed66751

File tree

6 files changed

+243
-336
lines changed

6 files changed

+243
-336
lines changed

rxjava-contrib/rxjava-computation-expressions/src/main/java/rx/Statement.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import java.util.Map;
1919

2020
import rx.functions.Func0;
21-
import rx.operators.OperationConditionals;
21+
import rx.operators.OperatorIfThen;
22+
import rx.operators.OperatorSwitchCase;
23+
import rx.operators.OperatorWhileDoWhile;
2224

2325
/**
2426
* Imperative statements expressed as Observable operators.
2527
*/
26-
public class Statement {
27-
28+
public final class Statement {
29+
private Statement() { throw new IllegalStateException("No instances!"); }
2830
/**
2931
* Return a particular one of several possible Observables based on a case
3032
* selector.
@@ -99,7 +101,7 @@ public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
99101
public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
100102
Map<? super K, ? extends Observable<? extends R>> mapOfCases,
101103
Observable<? extends R> defaultCase) {
102-
return Observable.create(OperationConditionals.switchCase(caseSelector, mapOfCases, defaultCase));
104+
return Observable.create(new OperatorSwitchCase<K, R>(caseSelector, mapOfCases, defaultCase));
103105
}
104106

105107
/**
@@ -116,8 +118,8 @@ public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
116118
* Observable, and then continues to replay them so long as the post
117119
* condition is true
118120
*/
119-
public static <T> Observable<T> doWhile(Observable<T> source, Func0<Boolean> postCondition) {
120-
return Observable.create(OperationConditionals.doWhile(source, postCondition));
121+
public static <T> Observable<T> doWhile(Observable<? extends T> source, Func0<Boolean> postCondition) {
122+
return Observable.create(new OperatorWhileDoWhile<T>(source, TRUE, postCondition));
121123
}
122124

123125
/**
@@ -132,8 +134,8 @@ public static <T> Observable<T> doWhile(Observable<T> source, Func0<Boolean> pos
132134
* @return an Observable that replays the emissions from the source
133135
* Observable so long as <code>preCondition</code> is true
134136
*/
135-
public static <T> Observable<T> whileDo(Observable<T> source, Func0<Boolean> preCondition) {
136-
return Observable.create(OperationConditionals.whileDo(source, preCondition));
137+
public static <T> Observable<T> whileDo(Observable<? extends T> source, Func0<Boolean> preCondition) {
138+
return Observable.create(new OperatorWhileDoWhile<T>(source, preCondition, preCondition));
137139
}
138140

139141
/**
@@ -200,7 +202,16 @@ public static <R> Observable<R> ifThen(Func0<Boolean> condition, Observable<? ex
200202
*/
201203
public static <R> Observable<R> ifThen(Func0<Boolean> condition, Observable<? extends R> then,
202204
Observable<? extends R> orElse) {
203-
return Observable.create(OperationConditionals.ifThen(condition, then, orElse));
205+
return Observable.create(new OperatorIfThen<R>(condition, then, orElse));
206+
}
207+
/** Returns always true. */
208+
private static final class Func0True implements Func0<Boolean> {
209+
@Override
210+
public Boolean call() {
211+
return true;
212+
}
204213
}
205214

215+
/** Returns always true function. */
216+
private static final Func0True TRUE = new Func0True();
206217
}

rxjava-contrib/rxjava-computation-expressions/src/main/java/rx/operators/OperationConditionals.java

Lines changed: 0 additions & 324 deletions
This file was deleted.

0 commit comments

Comments
 (0)