### Question:
Enumerables { public static <E, TKey, TResult> Enumerable<TResult> match( Enumerable<E> enumerable, final Function1<E, TKey> keySelector, Matcher<E> matcher, Emitter<E, TResult> emitter, int history, int future) { return new AbstractEnumerable<TResult>() { public Enumerator<TResult> enumerator() { return new Enumerator<TResult>() { final Enumerator<E> inputEnumerator = enumerable.enumerator(); final Map<TKey, Matcher.PartitionState<E>> partitionStates = new HashMap<>(); int inputRow = -1; final Deque<TResult> emitRows = new ArrayDeque<>(); TResult resultRow; final AtomicInteger matchCounter = new AtomicInteger(1); public TResult current() { Objects.requireNonNull(resultRow); return resultRow; } public boolean moveNext() { for (;;) { resultRow = emitRows.pollFirst(); if (resultRow != null) { return true; } if (!inputEnumerator.moveNext()) { return false; } ++inputRow; final E row = inputEnumerator.current(); final TKey key = keySelector.apply(row); final Matcher.PartitionState<E> partitionState = partitionStates.computeIfAbsent(key, k -> matcher.createPartitionState(history, future)); partitionState.getMemoryFactory().add(row); matcher.matchOne(partitionState.getRows(), partitionState, list -> emitter.emit(list, null, null, matchCounter.getAndIncrement(), emitRows::add)); } } public void reset() { throw new UnsupportedOperationException(); } public void close() { inputEnumerator.close(); } }; } }; } private  Enumerables(); static Enumerable<E> slice0(Enumerable<E[]> enumerable); static Enumerable<Row> toRow(final Enumerable<Object[]> enumerable); static Supplier<Enumerable<Row>> toRow(
      final Supplier<Enumerable<Object[]>> supplier); @SuppressWarnings("Guava") @Deprecated // to be removed before 2.0 static com.google.common.base.Supplier<Enumerable<Row>> toRow(
      final com.google.common.base.Supplier<Enumerable<Object[]>> supplier); static Enumerable<TResult> match(
      Enumerable<E> enumerable,
      final Function1<E, TKey> keySelector,
      Matcher<E> matcher,
      Emitter<E, TResult> emitter, int history, int future);  }### Answer:
@Test @Ignore public void testMatch() { final Enumerable<Emp> emps = Linq4j.asEnumerable( Arrays.asList( new Emp(20, "Theodore"), new Emp(10, "Fred"), new Emp(20, "Sebastian"), new Emp(30, "Joe"))); final Pattern p = Pattern.builder() .symbol("A") .symbol("B").seq() .build(); final Matcher<Emp> matcher = Matcher.<Emp>builder(p.toAutomaton()) .add("A", s -> s.get().deptno == 20) .add("B", s -> s.get().deptno != 20) .build(); final Enumerables.Emitter<Emp, String> emitter = (rows, rowStates, rowSymbols, match, consumer) -> { for (int i = 0; i < rows.size(); i++) { if (rowSymbols == null) { continue; } if ("A".equals(rowSymbols.get(i))) { consumer.accept( String.format(Locale.ENGLISH, "%s %s %d", rows, rowStates, match)); } } }; final Enumerable<String> matches = Enumerables.match(emps, emp -> 0L, matcher, emitter, 1, 1); assertThat(matches.toList().toString(), equalTo("[[Emp(20, Theodore), Emp(10, Fred)] null 1, " + "[Emp(20, Sebastian), Emp(30, Joe)] null 2]")); }