public static <T, K, U> AggregateOperation1<T, Map<K, U>, Map<K, U>> toMap(
            FunctionEx<? super T, ? extends K> keyFn,
            FunctionEx<? super T, ? extends U> valueFn
    ) {
        checkSerializable(keyFn, "keyFn");
        checkSerializable(valueFn, "valueFn");
        return toMap(keyFn, valueFn,
                (k, v) -> {
                    throw new IllegalStateException("Duplicate key: " + k);
                },
                HashMap::new);
    }
@Test
    public void when_toMapCombinesDuplicates_then_exception() {
        // Given
        AggregateOperation1<Entry<Integer, Integer>, Map<Integer, Integer>, Map<Integer, Integer>> op =
                toMap(Entry::getKey, Entry::getValue);
        BiConsumerEx<? super Map<Integer, Integer>, ? super Map<Integer, Integer>> combineFn = op.combineFn();
        assertNotNull("combineFn", combineFn);
        Map<Integer, Integer> acc1 = op.createFn().get();
        op.accumulateFn().accept(acc1, entry(1, 1));
        Map<Integer, Integer> acc2 = op.createFn().get();
        op.accumulateFn().accept(acc2, entry(1, 2));

        // When
        assertThrows(IllegalStateException.class, () -> combineFn.accept(acc1, acc2));
    }