Skip to content

Instantly share code, notes, and snippets.

@ponzao
Created February 18, 2011 09:20
Show Gist options
  • Save ponzao/833455 to your computer and use it in GitHub Desktop.
Save ponzao/833455 to your computer and use it in GitHub Desktop.
type ID = Long
type Code = String
class User(val id: ID,
val name: String,
val friends: List[User])
class UserDto(val code: Code,
val name: String,
val friends: List[UserDto]) {
override def toString = {
"UserDto(" + code + " " + name + " " + friends + ")"
}
}
implicit def idToCode(id: ID): Code = {
id.toString
}
implicit def userToUserDto(user: User): UserDto = {
new UserDto(user.id, user.name, user.friends)
}
implicit def usersToUserDtos(users: List[User]): List[UserDto] = {
users.map(userToUserDto)
}
val users = List(new User(10, "Vesa Marttila", Nil))
val userDtos: List[UserDto] = users
println(userDtos.head) // -> UserDto(10 Vesa Marttila List())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment