Created
November 12, 2021 14:37
-
-
Save fernandomora/737804416da3d836b096db38976fec48 to your computer and use it in GitHub Desktop.
mutable repo
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
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