Skip to content

Commit

Permalink
Conditional statements contribution to Operator
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd committed Apr 29, 2014
1 parent 95e0636 commit 6fe11aa
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import java.util.Map;

import rx.functions.Func0;
import rx.operators.OperationConditionals;
import rx.operators.OperatorIfThen;
import rx.operators.OperatorSwitchCase;
import rx.operators.OperatorWhileDoWhile;

/**
* Imperative statements expressed as Observable operators.
*/
public class Statement {

public final class Statement {
private Statement() { throw new IllegalStateException("No instances!"); }
/**
* Return a particular one of several possible Observables based on a case
* selector.
Expand Down Expand Up @@ -99,7 +101,7 @@ public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
Map<? super K, ? extends Observable<? extends R>> mapOfCases,
Observable<? extends R> defaultCase) {
return Observable.create(OperationConditionals.switchCase(caseSelector, mapOfCases, defaultCase));
return Observable.create(new OperatorSwitchCase<K, R>(caseSelector, mapOfCases, defaultCase));
}

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

/**
Expand All @@ -132,8 +134,8 @@ public static <T> Observable<T> doWhile(Observable<T> source, Func0<Boolean> pos
* @return an Observable that replays the emissions from the source
* Observable so long as <code>preCondition</code> is true
*/
public static <T> Observable<T> whileDo(Observable<T> source, Func0<Boolean> preCondition) {
return Observable.create(OperationConditionals.whileDo(source, preCondition));
public static <T> Observable<T> whileDo(Observable<? extends T> source, Func0<Boolean> preCondition) {
return Observable.create(new OperatorWhileDoWhile<T>(source, preCondition, preCondition));
}

/**
Expand Down Expand Up @@ -200,7 +202,16 @@ public static <R> Observable<R> ifThen(Func0<Boolean> condition, Observable<? ex
*/
public static <R> Observable<R> ifThen(Func0<Boolean> condition, Observable<? extends R> then,
Observable<? extends R> orElse) {
return Observable.create(OperationConditionals.ifThen(condition, then, orElse));
return Observable.create(new OperatorIfThen<R>(condition, then, orElse));
}
/** Returns always true. */
private static final class Func0True implements Func0<Boolean> {
@Override
public Boolean call() {
return true;
}
}

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

This file was deleted.

Loading

0 comments on commit 6fe11aa

Please sign in to comment.