Apache-Spark : What is map(_._2) shorthand for?

后端 未结 5 1023
予麋鹿
予麋鹿 2020-12-28 08:59

I read a project\'s source code, found:

val sampleMBR = inputMBR.map(_._2).sample

inputMBR is a tuple.

the function

5条回答
  •  情歌与酒
    2020-12-28 09:31

    collection.map(_._2) emits a second component of the tuple. Example from pure Scala (Spark RDDs work the same way):

    scala> val zipped = (1 to 10).zip('a' to 'j')
    zipped: scala.collection.immutable.IndexedSeq[(Int, Char)] = Vector((1,a), (2,b), (3,c), (4,d), (5,e), (6,f), (7,g), (8,h), (9,i), (10,j))
    
    scala> val justLetters = zipped.map(_._2)
    justLetters: scala.collection.immutable.IndexedSeq[Char] = Vector(a, b, c, d, e, f, g, h, i, j)
    

提交回复
热议问题