Last active
August 21, 2018 11:51
-
-
Save kunals201/01ac944b16b814f96363a1e483f41f44 to your computer and use it in GitHub Desktop.
tiny types with value classes
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
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