gpt4 book ai didi

scala - 单右箭头 (→) 对 Scala 中的集合意味着什么?

转载 作者:行者123 更新时间:2023-12-03 15:52:59 26 4
gpt4 key购买 nike

当我在 InteliJ 上的列表上使用自动完成功能时,它会显示一个向右的箭头,但没有说明其含义的文档。看起来像→。在一个例子中,它被称为:

val sampleList: List[String] = List("a", "b", "c");
sampleList.→()

我不知道括号里是什么,我也不能像 Spark 图一样使用它,所以这样做 s => s显示错误。以及 Scala 文档 online ,未列出箭头运算符。

这是它在自动完成时的显示方式
enter image description here

这个箭头运算符的示例用法是什么?

最佳答案

->没有专门定义在集合上,它是在 Any 上定义的(通过隐式类 ArrowAssoc )。你可以在 Predef.scala 中看到它的定义.

这是创建 Tuple2 的另一种语法。 :

scala> 1 -> 2
res0: (Int, Int) = (1,2)

scala> List().->(2)
res1: (List[Nothing], Int) = (List(),2)

scala> (1 -> 2) == ((1, 2))
res2: Boolean = true

关于scala - 单右箭头 (→) 对 Scala 中的集合意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49949257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com