Just replace _barnSize with (^. barnSize) or, equivalently, view barnSize :
someFunc :: Farm -> IntMap Size someFunc farm = view barnSize <$> farm ^. farmBarns
To solve the "100% lens" you can use the mapped setter. In this case, however, I do not think that there is a real advantage to this.
someFunc :: Farm -> IntMap Size someFunc farm = (mapped %~ view barnSize) (farm ^. farmBarns)
Another possible spelling involves using to to merge just one getter. This doesnβt buy you either, but it can be somewhat convenient if you want to continue working with the IntMap style in the lens by combining additional getters / bends, etc.
someFunc :: Farm -> IntMap Size someFunc farm = farm ^. farmBarns . to (fmap (view barnSize))
There is a special purpose combinator that includes the combination to / (^.) . It is called views :
someFunc :: Farm -> IntMap Size someFunc farm = views farmBarns (fmap (view barnSize)) farm
source share