You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have deep hierarchal object that I need to validate. My question is how to accumulate and validate all validations in the data structure in one traversal?
In the below example, suppose I want to vaildate OrderDocument and OrderItem in one traversal, how to compose, traverse and add multiple validation in lens composition?
final Lens<Order, List<OrderDocument>> orderDocumentsLens =
Lens.lens(Order::getOrderDocuments, ds -> cr -> cr.withOrderDocuments(ds));
final Lens<OrderDocument, List<OrderItem>> orderItemsLens =
Lens.lens(OrderDocument::getOrderItems, is -> crd -> crd.withOrderItems(is));
final Lens<OrderItem, List<OrderItemProperties>> orderItemPropertiesLens =
Lens.lens(OrderItem::getOrderItemProperties, sls -> i -> i.withOrderItemProperties(sls));
final List<String> fail = orderDocumentsLens.composeTraversal(List.Optic.traversal())
.composeLens(orderItemsLens).composeTraversal(List.Optic.traversal())
.composeLens(orderItemPropertiesLens).composeTraversal(List.Optic.traversal())
.modifyValidationF(Semigroup.stringSemigroup, this::validateItemProperties)
.f(order)
.accumulate().fail();
private Validation<String, OrderItemProperties> validateItemProperties(OrderItemProperties properties) {
return Validation.success(properties);
}
The text was updated successfully, but these errors were encountered:
I have deep hierarchal object that I need to validate. My question is how to accumulate and validate all validations in the data structure in one traversal?
In the below example, suppose I want to vaildate OrderDocument and OrderItem in one traversal, how to compose, traverse and add multiple validation in lens composition?
The text was updated successfully, but these errors were encountered: