4 ms·
I believe this is a case where a named tuple of functions, a record, is better than an interface. public record Lens<A, B>(Function<A, B> get, BiFunction<A
by _old_dude_ 4y ago
I believe this is a case where a named tuple of functions, a record, is better than an interface.
public record Lens<A, B>(Function<A, B> get, BiFunction<A, B, A> with) {
public <C> Lens<A, C> compose(Lens<B, C> inner) {
return new Lens<>(
inner.get.compose(get),
(a, c) -> with.apply(a, inner.with.apply(get.apply(a), c)));
}
}
Lens<Confirmation, LocalDateTime> $updatedOn =
new Lens<>(Confirmation::updateOn, Confirmation::updateOn);