λ Tony's blog λ
The weblog of Tony Morris

Project Euler Problem 1 Functional Java

Posted on October 3, 2008, in Programming, Project Euler

Project Euler Problem 1 using Functional Java:

import static fj.pre.Monoid.intAdditionMonoid;
import static fj.data.List.range;
import fj.F;

...

final int problem1 = intAdditionMonoid.sumLeft(range(0, 1000).filter(new F<Integer, Boolean>() {
  public Boolean f(final Integer a) {
    return a % 3 == 0 || a % 5 == 0;
  }
}));