Slide 75
Slide 75 text
Destructuring State impl
public class Logger {
private final Consumer error, warning;
private final Logger quiet, normal;
private Logger(Consumer error, Consumer warning,
Function quietFactory,
Function chattyFactory) {
this.error = error;
this.warning = warning;
this.quiet = quietFactory.apply(this);
this.chatty = chattyFactory.apply(this);
}
public Logger quiet() { return quiet; }
public Logger chatty() { return chatty; }
public static Logger logger(Consumer consumer) {
Objects.requireNonNull(consumer);
return new Logger(consumer, consumer,
chatty -> new Logger(consumer, msg -> { /*empty*/ }, identity(), it -> chatty),
identity());
}
} import static java.util.function.Function.identity