I search of method to resolve this initialization problem of tuple () with result of a map, like this :
//My current state of cities
val listOfCity = IndexedSeq(new City1(), new City2())
// Function which compute my new state
val (newCity,exchange) = listOfCity.map{ city => computeNewCity(city,listOfCity)}
The variable newCity contain the result ._1 of my tuple returned by computeNewCity() and the variable exchange contain the result ._2 of the same tuple.
The function computeNewCity() return a new version of my object city and an history of exchange, results of my exchange with other cities in listOfCity, it’s a tuple of type (City, Exchange)
How can i make this with help of functionnal programming ?
Thanks !
Sr
The problem is
listOfCity.map{ city => computeNewCity(city,listOfCity)}returns anIndexedSeq[(City, Exchange)](one tuple for each city inlistOfCity), and obviously you can’t just assign it to a(City, Exchange)tuple. You could take first element or last:or get a tuple of two sequences (cities and their corresponding exchanges)