types -package:optparse-applicative package:generic-lens
Traverse all types in the given structure.
For example, to update all
Strings in a
WTree (Maybe
String) String, we can write
>>> myTree = WithWeight (Fork (Leaf (Just "hello")) (Leaf Nothing)) "world"
>>> over (types @String) (++ "!") myTree
WithWeight (Fork (Leaf (Just "hello!")) (Leaf Nothing)) "world!"
The traversal is
deep, which means that not just the immediate
children are visited, but all nested values too.
Derive traversals of a given type in a product.
This function should never be used directly, only to override the
default traversal behaviour. To actually use the custom traversal
strategy, see typesUsing. This is because typesUsing
does additional optimisations, like ensuring that nodes with no
relevant members will not be traversed at runtime.
By adding instances to this class, we can override the default
behaviour in an ad-hoc manner. For example:
instance HasTypesCustom Custom Opaque Opaque String String where
typesCustom f (Opaque str) = Opaque $ f str