Skip to content

Instantly share code, notes, and snippets.

@WadeWaldron
Created August 28, 2015 15:01
Show Gist options
  • Save WadeWaldron/8edb82128e6bcba9e628 to your computer and use it in GitHub Desktop.
Save WadeWaldron/8edb82128e6bcba9e628 to your computer and use it in GitHub Desktop.
2015-08-28-DataStoreAbstractions-MigratingUserStore
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