class FormatJoinHelper implements Helper<Collection<?>> {

    @Override
    public Object apply(Collection<?> context, Options options) {
        if (context == null || context.isEmpty()) {
            return "";
        }

        String separator = options.hash("sep", ",");
        String format = options.hash("format", null);

        Function<Object, String> formatter = format != null
                ? each -> String.format(format, each)
                : Object::toString;

        return context.stream()
                .map(formatter)
                .collect(joining(separator));
    }

}