package com.github.davidmoten.rx;

import rx.Observable;
import rx.Scheduler;
import rx.functions.Func1;

public final class Functions {

    private Functions() {
        // do nothing
    }

    public static <T> Func1<T, T> identity() {
        return new Func1<T, T>() {
            @Override
            public T call(T t) {
                return t;
            }
        };
    }

    public static <T> Func1<T, Boolean> alwaysTrue() {
        return new Func1<T, Boolean>() {
            @Override
            public Boolean call(T t) {
                return true;
            }
        };
    }

    public static <T> Func1<T, Boolean> alwaysFalse() {
        return new Func1<T, Boolean>() {
            @Override
            public Boolean call(T t) {
                return false;
            }
        };
    }

    public static <T, R> Func1<T, R> constant(final R r) {
        return new Func1<T, R>() {
            @Override
            public R call(T t) {
                return r;
            }
        };
    }

    public static <T> Func1<T, Boolean> not(final Func1<T, Boolean> f) {
        return new Func1<T, Boolean>() {
            @Override
            public Boolean call(T t) {
                return !f.call(t);
            }
        };
    }

    /**
     * <p>
     * Returns a function that is expected to be used for performing parallel
     * processing of an observable sequence via flatMap for instance. For
     * example:
     * </p>
     * 
     * <code>source.flatMap(parallel(Schedulers.computation()));</code>
     * 
     * @param scheduler
     *            to be used for subscription to the function input
     * @return each t is mapped to a single element observable using the given
     *         Scheduler for subscription
     */
    public static <T> Func1<T, Observable<T>> parallel(final Scheduler scheduler) {
        return new Func1<T, Observable<T>>() {
            @Override
            public Observable<T> call(T t) {
                return Observable.just(t).subscribeOn(scheduler);
            }
        };
    }

    public static <T> Func1<T, Observable<T>> just() {
        return new Func1<T, Observable<T>>() {
            @Override
            public Observable<T> call(T t) {
                return Observable.just(t);
            }
        };
    }

    public static <T> Func1<Iterable<T>, Observable<T>> iterableToObservable() {
        return new Func1<Iterable<T>, Observable<T>>() {
            @Override
            public Observable<T> call(Iterable<T> iterable) {
                return Observable.from(iterable);
            }
        };
    }
}

@@ -1272,812 +1272,8 @@
  %7D%0A%0A
-    /**%0A     * %3Cp%3E%0A     * Returns a function that is expected to be used for performing parallel%0A     * processing of an observable sequence via flatMap for instance. For%0A     * example:%0A     * %3C/p%3E%0A     * %0A     * %3Ccode%3Esource.flatMap(parallel(Schedulers.computation()));%3C/code%3E%0A     * %0A     * @param scheduler%0A     *            to be used for subscription to the function input%0A     * @return each t is mapped to a single element observable using the given%0A     *         Scheduler for subscription%0A     */%0A    public static %3CT%3E Func1%3CT, Observable%3CT%3E%3E parallel(final Scheduler scheduler) %7B%0A        return new Func1%3CT, Observable%3CT%3E%3E() %7B%0A            @Override%0A            public Observable%3CT%3E call(T t) %7B%0A                return Observable.just(t).subscribeOn(scheduler);%0A            %7D%0A        %7D;%0A    %7D%0A%0A
     

Update Functions.java