Skip to content

Instantly share code, notes, and snippets.

@fernandomora
Created November 12, 2021 14:37
Show Gist options
  • Save fernandomora/737804416da3d836b096db38976fec48 to your computer and use it in GitHub Desktop.
Save fernandomora/737804416da3d836b096db38976fec48 to your computer and use it in GitHub Desktop.
mutable repo
object Main extends App {
case class User(id: String, name: String)
val users = scala.collection.mutable.Map(
"1" -> User("1", "Fernando"),
"2" -> User("1", "Darren"),
)
object UserRepository {
def getUserById(id: String): Option[User] = {
users.get(id)
}
def insertUser(id: String, user: User): Unit = {
users.put(id, user)
()
}
}
val user = UserRepository.getUserById("1").get
UserRepository.insertUser("1", user.copy("1", "Fernando 2"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment