Inverse of Supplier<T> in Guava
Your alternatives are:
- Java 8 introduces a
Consumer
interface which you can compose. - Xtend's standard library contains
Procedures
. - Scala has
Function*
; if a function's return type isUnit
, it is considered a side effect.
In all of these languages, you can use functional interfaces conveniently, so you could also use e.g. Functional Java's Effect
.
Otherwise, you better rely on existing language constructs for performing side effects, e.g. the built-in for
loop. Java < 8 inflicts tremendous syntactic overhead when using lambdas. See this question and this discussion.