Skip to content

Instantly share code, notes, and snippets.

@kunals201

kunals201/Tweet.scala

Last active Aug 21, 2018
Embed
What would you like to do?
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