T
- the type of the input which is passed to the consumer and executed once.public final class OnceConsumer<T>
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
applyOnce(java.util.function.Consumer<T> consumer)
Apply a computation on subject only once.
|
static <T> OnceConsumer<T> |
of(T t)
Create a do once consumer.
|
public static <T> OnceConsumer<T> of(T t)
T
- type of input on which operation is applied.t
- input which is passed to operationpublic void applyOnce(java.util.function.Consumer<T> consumer)
List<String> lst = new ArrayList<>();
OnceConsumer<List<String>> once = OnceConsumer.of(lst);
once.applyOnce((l) -> l.add("Hello World"));
once.applyOnce((l) -> l.add("Hello World"));
assertThat(lst).hasSize(1).contains("Hello World");
consumer
- computation run once with input t