Created
September 23, 2019 08:57
-
-
Save NikitaMelnikov/13a2edfae89c5f3742c9b72396c2f097 to your computer and use it in GitHub Desktop.
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
package demo | |
import java.util.concurrent.atomic.AtomicInteger | |
class IdGenerator { | |
private val seq = new AtomicInteger(0) | |
def next(): Int = seq.incrementAndGet() | |
} | |
final case class Visitor(id: Int) | |
object Conference { | |
def apply(title: String, size: Int)(implicit generator: IdGenerator): Conference = { | |
Conference(title, (1 to size).map(_ => Visitor(generator.next())).toList) | |
} | |
} | |
final case class Conference(title: String, visitors: List[Visitor]) | |
object Main extends App { | |
implicit val generator = new IdGenerator() | |
val conference = Conference("Scala Russia 2019", 10) | |
println(s"Welcome to ${conference.title}, ${conference.visitors}!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment