Skip to content

Instantly share code, notes, and snippets.

@tim2CF
Created April 29, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim2CF/8688bff51440a8ce667ec395d2ba6039 to your computer and use it in GitHub Desktop.
Save tim2CF/8688bff51440a8ce667ec395d2ba6039 to your computer and use it in GitHub Desktop.
-- pseudo-code, let's consider these types have corresponding lensens
-- from package proto-lens https://github.com/google/proto-lens
data Foo = Foo{foo: Maybe Bar}
data Bar = Bar{bar: Maybe Buz}
data Buz = Buz{buz: Buf}
data Buf = Buf
-- I'm using bind here to handle Maybe
-- Is there better/shorter way to do it
-- with some lens-specific functions?
accessBuf :: Foo -> Maybe Buf
accessBuf x =
(x ^. maybe'foo)
>>= (^. maybe'bar)
>>= (Just . (^. buz))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment