Closed haifengkao closed 3 years ago
When you have a field that has an optional type, there is an optic to address this fact. You can look for Optional
(in the last released version), which has been renamed to AffineTraversal
in the next release we will do.
You can check the documentation of how to write your own AffineTraversal
/Optional
and [how to get it automatically]. Also, we have documented its API.
In your particular example, and using Bow 0.8.0, it would be something like:
struct Handle: AutoOptional {}
struct Door: AutoOptional {
var handle: Handle?
}
struct Car: AutoOptional {
var door: Door?
}
Car.optional(for: \.door) + Door.optional(for: \handle)
thanks 😘
suppose I have the following structures:
I can use
Car.lens(for: \.door)
to getLens<Car, Door?>
Door.lens(for: \.handle)
to getLens<Door, Handle?>
but when I connect the two
Car.lens(for: \.door)
+Door.lens(for: \.handle)
the compiler will tell me type mismatchHow do I connect these lens?