import static rx.Observable.just;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import rx.Observable;
import rx.Observable.Transformer;
import rx.Observer;
import rx.functions.Action2;
import rx.functions.Func0;
import rx.functions.Func3;

import com.github.davidmoten.rx.Transformers;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Observable<Integer> source = just(1, 1, 1, 2, 2, 3);

        Func0<List<Integer>> initialState = () -> Collections.emptyList();

        Func3<List<Integer>, Integer, Observer<List<Integer>>, List<Integer>> transition = (list,
                n, observer) -> {
            if (list.size() == 0)
                return add(list, n);
            else if (list.get(0).equals(n)) {
                return add(list, n);
            } else {
                observer.onNext(list);
                return Collections.singletonList(n);
            }

        };
        Action2<List<Integer>, Observer<List<Integer>>> completionAction = (list, observer) -> {
            if (list.size() > 0) {
                observer.onNext(list);
            }
        };
        Transformer<Integer, List<Integer>> transformer = Transformers
                .<List<Integer>, Integer, List<Integer>> stateMachine(initialState, transition,
                        completionAction);
        System.out.println(source.compose(transformer).toList().toBlocking().single());
    }

    private static <T> List<T> add(List<T> list, T item) {
        List<T> result = new ArrayList<T>(list);
        result.add(item);
        return result;
    }
}

@@ -242,16 +242,43 @@
 .Func0;%0A
+import rx.functions.Func2;%0A
 import r
@@ -511,26 +511,303 @@
     
-Func0%3CList%3CInteger
+List%3CList%3CInteger%3E%3E lists = source.compose(toListUntilChanged((a, b) -%3E a.equals(b)))%0A                .toList().toBlocking().single();%0A        System.out.println(lists);%0A    %7D%0A%0A    public static %3CT%3E Transformer%3CT, List%3CT%3E%3E toListUntilChanged(Func2%3CT, T, Boolean%3E together) %7B%0A        Func0%3CList%3CT
 %3E%3E i
@@ -871,33 +871,21 @@
 c3%3CList%3C
-Integer%3E, Integer
+T%3E, T
 , Observ
@@ -892,23 +892,17 @@
 er%3CList%3C
-Integer
+T
 %3E%3E, List
@@ -898,31 +898,25 @@
 t%3CT%3E%3E, List%3C
-Integer
+T
 %3E%3E transitio
@@ -925,32 +925,16 @@
 = (list,
-%0A               
  n, obse
@@ -980,87 +980,53 @@
 == 0
-)%0A                return add(list, n);%0A            else if (list.get(0).equals(
+ %7C%7C together.call(list.get(list.size() - 1), 
 n)) 
@@ -1224,23 +1224,17 @@
 n2%3CList%3C
-Integer
+T
 %3E, Obser
@@ -1242,23 +1242,17 @@
 er%3CList%3C
-Integer
+T
 %3E%3E%3E comp
@@ -1399,295 +1399,83 @@
     
-Transformer%3CInteger, List%3CInteger%3E%3E transformer = Transformers%0A                .%3CList%3CInteger%3E, Integer, List%3CInteger%3E%3E stateMachine(initialState, transition,%0A                        completionAction);%0A        System.out.println(source.compose(transformer).toList().toBlocking().single()
+return Transformers.stateMachine(initialState, transition, completionAction
 );%0A 

add Transfomers.toListUntilChanged