I am currently trying to find my way into the world of Scala. Actually I am trying to implement a Round Robin strategy without mutable types.
I have an Scala Object with an initial list of hosts and a method to get the next host.
Object RoundRobin {
val optHosts: Option[List[String]] = Option[List[String]]("host1", "host2") // get from Configfile later
var hosts: List[String] = optHosts.getOrElse(List())
def url: String = {
hosts = hosts.tail ++ List(hosts.head)
hosts(0)
}
def execute = ??? // do something with the next host
}
I have read about immutable Queues in Scala but I don't really know how to solve this problem with immutable types. Somehow I would have to remember an index right? Is that one of the cases where it doesn't make sense to use immutable types?