Apache-Spark:map(_._ 2)的简写是什么? [英] Apache-Spark : What is map(_._2) shorthand for?

查看:235
本文介绍了Apache-Spark:map(_._ 2)的简写是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了一个项目的源代码,发现:

I read a project's source code, found:

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

inputMBR是一个元组.

函数map的定义是:

map[U classTag](f:T=>U):RDD[U]

似乎map(_._2)map(x => (x._2))的简写.

任何人都可以告诉我这些速记的规则吗?

Anyone can tell me rules of those shorthand ?

推荐答案

_语法可能有点令人困惑.单独使用_时,它表示匿名函数中的参数.因此,如果我们在配对上工作: map(_._2 + _._2)map(x, y => x._2 + y._2)的简写.当_用作函数名称(或值名称)的一部分时,它没有特殊含义.在这种情况下,x._2返回一个元组的第二个元素(假设x是一个元组).

The _ syntax can be a bit confusing. When _ is used on its own it represents an argument in the anonymous function. So if we working on pairs: map(_._2 + _._2) would be shorthand for map(x, y => x._2 + y._2). When _ is used as part of a function name (or value name) it has no special meaning. In this case x._2 returns the second element of a tuple (assuming x is a tuple).

这篇关于Apache-Spark:map(_._ 2)的简写是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆