class Lists {

  public static <X> List<X> distinct(List<X> inputs) {
    if (null == inputs) {
      return null;
    }

    return foldLeft(new ArrayList<X>(), inputs, new Aggregator<X, List<X>>() {
      private Set<X> mSeen = new HashSet<X>();

      @Override
      public List<X> eval(X input, List<X> out) {
        if (!mSeen.contains(input)) {
          out.add(input);
          mSeen.add(input);
        }
        return out;
      }
    });
  }

}

class TestLists {

  @Test
  public void testDistinct3() {

    List<String> inputs = new ArrayList<String>();
    inputs.add("a");
    inputs.add("b");
    inputs.add("c");

    assertTrue(inputs.equals(Lists.distinct(inputs)));

    inputs.clear();
    assertTrue(inputs.equals(Lists.distinct(inputs)));
  }

}