class EvaluationPhaseFilterFunctions {

    public static FunctionalSet<ValueTuple> matchesAtLeastCountOf(Object... args) {
        FunctionalSet<ValueTuple> matches = new FunctionalSet<>();
        // first arg is the count
        Integer count = Integer.parseInt(args[0].toString());
        // next arg is the field name
        Object fieldValue = args[1];
        // the rest of the args are the possible matches
        for (int i = 2; i < args.length; i++) {
            String regex = args[i].toString();
            if (fieldValue instanceof Iterable) {
                // cast as Iterable in order to call the right includeRegex method
                matches.addAll(includeRegex((Iterable) fieldValue, regex));
            } else {
                matches.addAll(includeRegex(fieldValue, regex));
            }
            if (matches.size() >= count) {
                break;
            }
        }
        if (matches.size() < count) {
            matches.clear();
        }
        return FunctionalSet.unmodifiableSet(matches);
    }

}