package com.github.davidmoten.rx;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import rx.Observable;
import rx.Observer;
import rx.functions.Func1;

public class RxUtil {

	private static final Logger log = LoggerFactory.getLogger(RxUtil.class);

	public static final <T> Func1<T, T> println() {
		return new Func1<T, T>() {
			@Override
			public T call(T t) {
				System.out.println(t);
				return t;
			}
		};
	}

	/**
	 * The first sequence will be emitted in its entirety and ignored before o2
	 * starts emitting.
	 * 
	 * @param o1
	 * @param o2
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> Observable<T> concatButIgnoreFirstSequence(
			Observable<?> o1, Observable<T> o2) {
		return Observable.concat((Observable<T>) o1.ignoreElements(), o2);
	}

	/**
	 * Logs errors and onNext at info level using slf4j {@link Logger}.
	 * 
	 * @return
	 */
	public static <T> Observer<? super T> log() {
		return new Observer<T>() {

			@Override
			public void onCompleted() {
				// do nothing
			}

			@Override
			public void onError(Throwable e) {
				log.error(e.getMessage(), e);
			}

			@Override
			public void onNext(T t) {
				log.info(t + "");
			}
		};
	}

	/**
	 * Returns a constant value.
	 * 
	 * @param s
	 * @return
	 */
	public static <R, S> Func1<R, S> constant(final S s) {
		return new Func1<R, S>() {
			@Override
			public S call(R t1) {
				return s;
			}
		};
	}

}

@@ -160,294 +160,265 @@
 1;%0A%0A
-public class RxUtil %7B%0A%0A%09private static final Logger log = LoggerFactory.getLogger(RxUtil.class);%0A%0A%09public static final %3CT%3E Func1%3CT, T%3E println() %7B%0A%09%09return new Func1%3CT, T%3E() %7B%0A%09%09%09@Override%0A%09%09%09public T call(T t) %7B%0A%09%09%09%09System.out.println(t);%0A%09%09%09%09return t;%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%0A%09/**%0A%09 * T
+/**%0A * Utility methods for use with RxJava library.%0A */%0Apublic class RxUtil %7B%0A%0A%09/**%0A%09 * slf4j logger.%0A%09 */%0A%09private static final Logger log = LoggerFactory.getLogger(RxUtil.class);%0A%0A%09/**%0A%09 * Returns the concatenation of two %7B@link Observable%7Ds but t
 he first
  seq
@@ -413,16 +413,20 @@
 he first
+%0A%09 *
  sequenc
@@ -484,19 +484,19 @@
 e o2
-%0A%09 *
  starts
+%0A%09 *
  emi
@@ -529,17 +529,108 @@
 %09 * 
-@param o2
+           the sequence to ignore%0A%09 * @param o2%0A%09 *            the sequence to emit after o1 ignored
 %0A%09 *

add javadoc