Search code examples
haskellhaskell-lens

How do I combine lenses which contain context?


I'm starting from authorityL via authorityHostL to hostBSL - I know you can combine lenses via

(authorityL . authorityHostL . hostBSL)

but that fails with Couldn't match type ‘Authority’ with ‘Maybe Authority’. How do I properly deal with the Maybe here?


Solution

  • You can add a _Just in between to only focus in on the successful results.

    (authorityL . _Just . authorityHostL . hostBSL)
    

    does the trick like it's said in the comments.