Skip to content

Instantly share code, notes, and snippets.

@kunals201
Last active August 21, 2018 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunals201/01ac944b16b814f96363a1e483f41f44 to your computer and use it in GitHub Desktop.
Save kunals201/01ac944b16b814f96363a1e483f41f44 to your computer and use it in GitHub Desktop.
tiny types with value classes
case class UserId(id: Int) extends AnyVal
case class Username(name: String) extends AnyVal
case class TweetId(id: Int) extends AnyVal
case class TweetContent(content: String) extends AnyVal
case class User(id: UserId, name: Username)
case class Tweet(id: TweetId, content: TweetContent)
object Test extends App {
val user = User(UserId(1), Username("kunal"))
val tweet = Tweet(TweetId(10), TweetContent("ABC"))
println(s"userID :- ${user.id}")
println(s"tweetID:- ${tweet.content}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment