class ArrayExcept {

  @Udf
  public <T> List<T> except(
      @UdfParameter(description = "Array of values") final List<T> left,
      @UdfParameter(description = "Array of exceptions") final List<T> right) {
    if (left == null || right == null) {
      return null;
    }
    final Set<T> distinctRightValues = new HashSet<>(right);
    final Set<T> distinctLeftValues = new LinkedHashSet<>(left);
    final List<T> result = distinctLeftValues
        .stream()
        .filter(e -> !distinctRightValues.contains(e))
        .collect(Collectors.toList());
    return result;
  }

}