Java implementation of monads