Making Lenses Practical in Java
chriskiehl.com
Making Lenses Practical in Java
1–10 of 108 posts
Re: Making Lenses Practical in Java
#2Re: Making Lenses Practical in Java
#3Re: Making Lenses Practical in Java
#4https://github.com/chriskiehl/Deoplice
Re: Making Lenses Practical in Java
#5Edit: The code in the article would become something like
pendingOrders.map(order -> {
copy = order.DeepCopy();
copy.getApproval()
.getConfirmation()
.setUpdatedOn(LocalDateTime.now()));
return copy;
}
)
(of course, we could also get rid of the getters and setters and replace them with direct field access, if we take the data class concept seriously)Re: Making Lenses Practical in Java
#6I just use Kotlin. Never looked back.
Re: Making Lenses Practical in Java
#7 public record Lens(Function get, BiFunction with) {
public Lens compose(Lens inner) {
return new Lens(
inner.get.compose(get),
(a, c) -> with.apply(a, inner.with.apply(get.apply(a), c)));
}
}
Lens $updatedOn =
new Lens(Confirmation::updateOn, Confirmation::updateOn);Re: Making Lenses Practical in Java
#8The problem this is trying to resolve is creating copies of a complex immutable class with some deep fields changed. I do have to wonder for a case like this if using a mutable object with a deep copy function wouldn't be a better solution, rather than adding extra magic to do it more easily as possible... Edit: The code in the article would become something like pendingOrders.map(order -> { copy = order.DeepCopy();…
Lenses are "smart" in the sense that they only copy what's necessary.
Re: Making Lenses Practical in Java
#9Re: Making Lenses Practical in Java
#10I don't agree on the fact that lombok has brought us out of the dark ages. We used to use it, but it has some drawbacks. One of them, it's an additional dependency. This, for a simple thing such as pojo, seems a bit overkill to me. The additional amount of time used to write some cose isn't worth the risk of additional bugs hidden in having one more dependency.