(
^.) applies a getter to a value; in other words, it gets a
value out of a structure using a getter (which can be a lens,
traversal, fold, etc.).
Getting 1st field of a tuple:
(^. _1) :: (a, b) -> a
(^. _1) = fst
When (
^.) is used with a traversal, it combines all results
using the
Monoid instance for the resulting type. For instance,
for lists it would be simple concatenation:
>>> ("str","ing") ^. each
"string"
The reason for this is that traversals use
Applicative, and the
Applicative instance for
Const uses monoid concatenation
to combine “effects” of
Const.
A non-operator version of (
^.) is called
view, and
it's a bit more general than (
^.) (it works in
MonadReader). If you need the general version, you can get it
from
microlens-mtl; otherwise there's
view available in
Lens.Micro.Extras.