Last active
January 6, 2016 00:18
-
-
Save sullivan-/41ff71b3d943c00d3045 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
trait UserService { | |
def updateScoreCard(user: User, event: PointScoredEvent): User | |
} | |
val userService: UserService = getUserService() | |
val userState: PState[User] = getUserState() | |
val updatedState: PState[User] = userState.map { user => | |
userService.updateScoreCard(user, event) | |
} | |
def applyEvent(event: PointScoredEvent): FPState[User] = { | |
val futureOptUserState: FOPState[User] = | |
userRepo retrieve User.usernameKey(event.username) | |
futureOptUserState flatMap { optUserState => | |
val userState: PState[User] = optUserState getOrElse { | |
throw new UserNotFoundException(event.username) | |
} | |
val updatedState: PState[User] = | |
userState map userService.updateUser | |
userRepo update updatedState | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment