import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;

public class PushStream<T> {
    private Function<Function<T, Void>, Void> sF = null;

    public PushStream(Function<Function<T, Void>, Void> sf) {
        sF = sf;
    }

    public List<T> toList() {
        List<T> acc = new LinkedList<>();
        sF.apply(v -> {
            acc.add(v);
            return null;
        });

        return acc;
    }

    public <R> PushStream<R> map(Function<T, R> f) {
        Function<Function<R, Void>, Void> new_sF = (Function<R, Void> iterf) ->
        {
            sF.apply(v -> iterf.apply(f.apply(v)));
            return null;
        };
        return new PushStream(new_sF);
    }

    public static <T> PushStream<T> of(List<T> xs) {
        Function<Function<T, Void>, Void> new_sF = (Function<T, Void> iterf) ->
        {
            for (T t : xs) {
                iterf.apply(t);
            }
            return null;
        };
        return new PushStream(new_sF);
    }

}