package com.timgroup.eventsubscription;

import com.timgroup.eventstore.api.Position;
import org.joda.time.DateTime;

public interface EventHandler<T> {
    default void apply(T deserialized) {}

    default void apply(Position position, DateTime timestamp, T deserialized, boolean endOfBatch) {
        apply(deserialized);
    }

    @SafeVarargs
    static <E> EventHandler<E> concat(EventHandler<E>... handlers) {
        return new EventHandler<E>() {
            @Override
            public void apply(E deserialized) {
                for (EventHandler<E> handler : handlers) {
                    handler.apply(deserialized);
                }
            }

            @Override
            public void apply(Position position, DateTime timestamp, E deserialized, boolean endOfBatch) {
                for (EventHandler<E> handler : handlers) {
                    handler.apply(position, timestamp, deserialized, endOfBatch);
                }
            }
        };
    }
}

@@ -34,16 +34,42 @@
 ption;%0A%0A
+import java.util.Arrays;%0A%0A
 import c
@@ -105,16 +105,16 @@
 sition;%0A
-
 import o
@@ -460,550 +460,59 @@
 new 
-EventHandler%3CE%3E() %7B%0A            @Override%0A            public void apply(E deserialized) %7B%0A                for (EventHandler%3CE%3E handler : handlers) %7B%0A                    handler.apply(deserialized);%0A                %7D%0A            %7D%0A%0A            @Override%0A            public void apply(Position position, DateTime timestamp, E deserialized, boolean endOfBatch) %7B%0A                for (EventHandler%3CE%3E handler : handlers) %7B%0A                    handler.apply(position, timestamp, deserialized, endOfBatch);%0A                %7D%0A            %7D%0A        %7D
+BroadcastingEventHandler%3C%3E(Arrays.asList(handlers))
 ;%0A  

implement EventHandler.concat using existing BroadcastingEventHandler