Scala - What does the map [(A, B)] mean?

I am reading a Scala Map document and am confused by this method signature

def zipAll[B](that: collection.Iterable[B], thisElem: A, thatElem: B): Map[(A, B)]

What does it mean Map[(A, B)]? Is it the same as Map[A, B]? Thanks

Link to the document:

http://www.scala-lang.org/api/current/scala/collection/immutable/Map.html

+4
source share
1 answer

I am reading a Scala Map document and am confused by this method signature

def zipAll[B](that: collection.Iterable[B], thisElem: A, thatElem: B): Map[(A, B)]

This is not a method signature. This is " use the signature for the occasion ." This is a simplified signature that indicates the most common use of the method. Real Signature:

def zipAll[B, A1 >: (K, V), That](that: GenIterable[B], thisElem: A1, thatElem: B)(implicit bf: CanBuildFrom[Map[K, V], (A1, B), That]): That

What does it mean Map[(A, B)]?

(A, B)is syntactic sugar for Tuple2[A, B], i.e. type of pair (aka 2-tuple).

Is that the same thing Map[A, B]?

, Map[Tuple2[A, B]] Map[A, B]: Map (A, B), Map , A B.

, Map , : Map , .

, , , , , . , .

, , . , Map.zipAll ( , zip Map).

, zip - that , - other :

Map("one"1, "two"2) zip Seq('a, 'b, 'c)
//=> Map((one, 1) -> 'a, (two, 2) -> 'b)

, :

def zipAll[A](that: collection.Iterable[A], thisElem: (K, V), thatElem: A): Map[(K, V), A]

, (K, V) A .

+3

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


All Articles