Created
January 4, 2019 20:19
-
-
Save mattroberts297/b89292fd3effcd9c6ce7017e230db209 to your computer and use it in GitHub Desktop.
SignupCore.scala
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
def signup | |
[F[_], A: IsParseable[F, ?], B: HasCodes] | |
(a: A): Signup[B] = { | |
for { | |
errorOrCode <- signupImpl(a) | |
_ <- errorOrCode.fold( | |
logError, | |
_ => Success.asRight[LogError] |> Signup.pure | |
) | |
} yield { | |
errorOrCode.left.map(errorToCode[B]).merge | |
} | |
} | |
def logError | |
(e: SignupError): Signup[LogError Or Success] = e match { | |
case ParseError => | |
log(info("Parse error")) | |
case CryptoError => | |
log(error("Unexpected cryptography error")) | |
case UnknownDatabaseError => | |
log(error("Unexpected database error")) | |
case DatabaseConflictError => | |
log(info("Database conflict")) | |
case LogError => | |
log(error("Unexpected logging error")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment