class CndExporter {

    static <T, E extends Throwable> void combineCauseMessages(final @NotNull Stream<Result<T>> results,
                                                              final @NotNull Class<? extends Throwable> causeType,
                                                              final @NotNull Class<E> andThrow) throws E {
        final String combined = results.filter(Result::isFailure)
                .map(result -> result.findCause(causeType))
                .filter(Optional::isPresent)
                .map(Optional::get)
                .map(Throwable::getMessage)
                .collect(Collectors.joining(", "));
        if (!combined.isEmpty()) {
            E rethrow;
            try {
                rethrow = andThrow.getConstructor(String.class).newInstance(combined);
            } catch (final ReflectiveOperationException e) {
                throw new IllegalStateException(combined, e);
            }
            throw rethrow;
        }
    }

    private  CndExporter(final List<Rule> scopeExportNames,
                        final List<Rule> scopeReplaceNames,
                        final boolean includeBuiltins);

}