Polysemy: Design heuristics: Grouping interpreters
In our previous log, we ended up with a lot of interpreters:
intrepretUserRegistration :: Member InternalUserEffect r => InterpreterFor UserRegistration r
intrepretUserRegistration =
interpret $
\case
SignUp userInfo password -> internalSignUp userInfo password
ConfirmSignUp confirmationInfo -> internalConfirmSignUp confirmationInfo
intrepretUserAuthenticationManagement :: Member InternalUserEffect r => InterpreterFor UserAuthenticationManagement r
intrepretUserAuthenticationManagement =
interpret $
\case
SignIn emailAddress password -> internalSignIn emailAddress password
SignOut token -> internalSignOut token
intrepretUserAuthenticationCheck :: Member InternalUserEffect r => InterpreterFor UserAuthenticationCheck r
intrepretUserAuthenticationCheck =
interpret $
\case
AuthenticateUser token -> internalAuthenticateUser token
We can leverage InterpretersFor to provide a single (and simpler) interpreter:
interpretAllUserEffectsCognito :: InterpretersFor '[UserRegistration, UserAuthenticationManagement, UserAuthenticationCheck] r
interpretAllUserEffectsCognito =
interpretInternalUserEffectCognito
. intrepretUserAuthenticationCheck
. intrepretUserAuthenticationManagement
. intrepretUserRegistration
. raise3Under @InternalUserEffect
See the full the code here.