Scala - zip with futures

Below is the code I'm trying to understand:

object Tryouts extends App{
    val studentIds= Future{
        List("s1","s2","s3")
    }
    val details = studentIds zip(Future{List("Tim","Joe","Fin")}).map(x=>x.tail)
    details.foreach(println)
    Thread.sleep(1000)

}

Problem:

val details = studentIds zipper (Future {List ("Tim", "Joe", "Rib")}). Mapping (x => x.tail)

Here, if you notice, I do not use ".". before zip and just giving a space. I think that. and the space works the same, and also checks for some stack overflow problems. the above expression before applying the map will lead me to the Future [(List [String], List [String])]. so when i say

.map (x = x.tail) should show a compilation error in the IDE, since the tail operation can only be used in a list, not a tuple. But it really succeeds.

, "." zip :

val details = studentIds.zip(Future {List ( "Tim", "Joe", "Fin" )}). map (x = > x.tail) (x = > x.tail) .

?

+4
1

( .), , , - map(x => x.tail) Future{List("Tim", "Joe", "Fin")}.

:

val y = 3 to(5).toDouble

#toDouble 5. , .

, . , :

val details = ids zip Future.successful(List("Tim", "Joe", "Fin")) map (_.tail)
// compile error: "Cannot resolve symbol tail"
+6

Source: https://habr.com/ru/post/1673290/


All Articles