Created
February 18, 2011 09:20
-
-
Save ponzao/833455 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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