Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created November 23, 2020 03:09
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 tonymorris/1bbc3aff874a97722d78cb9a9154c494 to your computer and use it in GitHub Desktop.
Save tonymorris/1bbc3aff874a97722d78cb9a9154c494 to your computer and use it in GitHub Desktop.
{-# LANGUAGE LambdaCase #-}
import Control.Lens
data UserInfo v b =
StartUpRemoteUser
{ _privateKey :: v -- ^ The startup key when the tree is created by the
-- administrator.
, _publicKey :: b -- ^ The public key of the remote user.
}
| RemoteUser
{
_publicKey :: b -- ^ The public key of the remote user.
}
| LocalUser
{ _privateKey :: v -- ^ The private key of the local user
, _publicKey :: b -- ^ The public key of the local user
}
deriving Eq
_StartUpRemoteUser ::
Prism'
(UserInfo v b)
(v, b)
_StartUpRemoteUser =
prism'
(\(v, b) -> StartUpRemoteUser v b)
(\case
StartUpRemoteUser v b -> Just (v, b)
_ -> Nothing
)
_StartUpRemoteUser_privateKey ::
Traversal'
(UserInfo v b)
v
_StartUpRemoteUser_privateKey =
_StartUpRemoteUser . _1
getPrivateKey ::
UserInfo v b
-> Maybe v
getPrivateKey =
preview _StartUpRemoteUser_privateKey
overPrivateKey ::
(v -> v)
-> UserInfo v b
-> UserInfo v b
overPrivateKey =
over _StartUpRemoteUser_privateKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment