Created
May 4, 2020 11:50
-
-
Save tim2CF/da8b0d4bed8d18d279c661cbf337dc12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 :: Bool, | |
buf :: Int, | |
bif :: Integer | |
} | |
-- I'm using bind here to handle Maybe | |
-- And compose Just values into tuple | |
-- Is there better/shorter way to do it | |
-- with some lens-specific functions? | |
-- Something applicative-like style for lens? | |
accessBuzBufBif :: Foo -> Maybe (Bool, Int, Integer) | |
accessBuzBufBif x = do | |
buz' <- x ^? mbar . buz | |
buf' <- x ^? mbar . buf | |
bif' <- x ^? mbar . bif | |
return (buz', buf', bif') | |
where | |
mbar = maybe'foo . _Just . maybe'bar . _Just |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment