Filtering data is not unusual when processing data set. Usually it involves the use of Functor, also known as Function Object. This we need two things. First an element, second a predicate.


So let's do it in #Java. We cannot use functions inside parameters in Java so we need to declare a predicate interface. Assuming we are not yet using Java 8 and cannot use Google Guava and let's minimize our Mutability

// Predicate Interface

public interface Predicate<T> {
  public boolean apply(T type);

// Filtering Function
public static <T> Collection <T> filter ( Collection<T> target, Predicate<T> predicate)
  Collection <T> result = new ArrayList<T>();
  for (T elem : target) {
    if (predicate.apply(elem)) {
  return result;

// Filter a list to return only odd lists w/ variable named intlist.
List<Integer> oddOnly = filter(intlist, new Predicate<Integer>()
  public boolean apply(Integer value) {
    return (value % 2 != 0)


And then let's do this in #Scala, assuming the name of the int we want to filter is intlist

intlist.filter(x => (x % 2 != 0))

Huwoow that's a lot of simplifications, but I think it's still too long make it even shorter

intlist.filter((_ % 2 != 0))

Let's get rid of that paren (I really hate paren) to make it easily readable.

intlist filter (_ % 2 != 0)


So how we do that in #Clojure? We don't need Google Guava or 3rd party libs to do so, even odd predicate is provided for us.

(filter odd? intlist)

So what do you think?