Created
August 28, 2015 15:01
-
-
Save WadeWaldron/8edb82128e6bcba9e628 to your computer and use it in GitHub Desktop.
2015-08-28-DataStoreAbstractions-MigratingUserStore
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
class MigratingUserStore(origin: UserStore, destination: UserStore) extends UserStore { | |
def find(userId: UserId): Option[User] = { | |
destination.find(userId) match { | |
case None => | |
origin.find(userId) | |
case result => | |
result.map(user => destination.save(user)) | |
} | |
} | |
def save(user: User): User = { | |
origin.save(user) | |
destination.save(user) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment