ChatGPT解决这个技术问题 Extra ChatGPT

Scala 的所有符号运算符是什么意思?

Scala 语法有很多符号。由于使用搜索引擎很难找到这些类型的名称,因此它们的完整列表会有所帮助。

Scala 中的所有符号是什么,每个符号的作用是什么?

特别是,我想了解 ->||=++=<=_._:::+=

以及 Staircase 第一版的索引,位于 >> artima.com/pins1ed/book-index.html#indexanchor
相关:运算符字符与字母数字字符:stackoverflow.com/questions/7656937/…
此外,如果存在您在 scalex 或楼梯书中找不到的“操作符”(主要是方法,其中一些类名使用中缀),例如“!!”,则可能的来源是 akka、scalaz 的 scaladocs和 sbt
使用中缀的类名示例(德语)>> raichoo.blogspot.com/2010/06/spass-mit-scala-infixtypen.html
关于搜索引擎过滤的问题,symbolhound.com 也是一个不错的选择

D
Daniel C. Sobral

出于教学的目的,我将运算符分为四类:

关键字/保留符号

自动导入的方法

常用方法

语法糖/组合物

幸运的是,大多数类别都出现在问题中:

->    // Automatically imported method
||=   // Syntactic sugar
++=   // Syntactic sugar/composition or common method
<=    // Common method
_._   // Typo, though it's probably based on Keyword/composition
::    // Common method
:+=   // Common method

大多数这些方法的确切含义取决于定义它们的类。例如,Int 上的 <= 表示 “小于或等于”。第一个,->,我将在下面给出示例。 :: 可能是在 List 上定义的方法(尽管它可能是同名对象),而 :+= 可能是在各种 Buffer 类上定义的方法。

所以,让我们看看他们。

关键字/保留符号

Scala 中有一些特殊的符号。其中两个被认为是正确的关键字,而其他的只是“保留”。他们是:

// Keywords
<-  // Used on for-comprehensions, to separate pattern from generator
=>  // Used for function types, function literals and import renaming

// Reserved
( )        // Delimit expressions and parameters
[ ]        // Delimit type parameters
{ }        // Delimit blocks
.          // Method call and path separator
// /* */   // Comments
#          // Used in type notations
:          // Type ascription or context bounds
<: >: <%   // Upper, lower and view bounds
<? <!      // Start token for various XML elements
" """      // Strings
'          // Indicate symbols and characters
@          // Annotations and variable binding on pattern matching
`          // Denote constant or enable arbitrary identifiers
,          // Parameter separator
;          // Statement separator
_*         // vararg expansion
_          // Many different meanings

这些都是语言的一部分,因此可以在任何正确描述该语言的文本中找到,例如 Scala Specification(PDF) 本身。

最后一个,下划线,值得特别描述一下,因为它被广泛使用,并且有很多不同的含义。这是一个示例:

import scala._    // Wild card -- all of Scala is imported
import scala.{ Predef => _, _ } // Exception, everything except Predef
def f[M[_]]       // Higher kinded type parameter
def f(m: M[_])    // Existential type
_ + _             // Anonymous function placeholder parameter
m _               // Eta expansion of method into method value
m(_)              // Partial function application
_ => 5            // Discarded parameter
case _ =>         // Wild card pattern -- matches anything
f(xs: _*)         // Sequence xs is passed as multiple parameters to f(ys: T*)
case Seq(xs @ _*) // Identifier xs is bound to the whole matched sequence

不过,我可能忘记了其他含义。

自动导入的方法

因此,如果您在上面的列表中没有找到您要查找的符号,那么它一定是一种方法,或者是其中的一部分。但是,通常,您会看到一些符号,并且该类的文档不会包含该方法。发生这种情况时,您正在查看一个或多个方法与其他方法的组合,或者该方法已导入范围,或者可通过导入的隐式转换获得。

这些仍然可以在 ScalaDoc 上找到:您只需要知道在哪里可以找到它们。或者,如果失败了,请查看 index(目前在 2.9.1 上被破坏,但在夜间可用)。

每个 Scala 代码都有三个自动导入:

// Not necessarily in this order
import _root_.java.lang._      // _root_ denotes an absolute path
import _root_.scala._
import _root_.scala.Predef._

前两个只使类和单例对象可用。第三个包含所有隐式转换和导入的方法,因为 Predef 本身就是一个对象。

查看 Predef 内部会快速显示一些符号:

class <:<
class =:=
object <%<
object =:=

任何其他符号都将通过隐式转换提供。只需查看带有 implicit 标记的方法,这些方法将接收该方法的类型对象作为参数接收。例如:

"a" -> 1  // Look for an implicit from String, AnyRef, Any or type parameter

在上述情况下,-> 是通过方法 any2ArrowAssoc 在类 ArrowAssoc 中定义的,该方法采用 A 类型的对象,其中 A 是同一方法的无界类型参数。

常用方法

因此,许多符号只是类上的方法。例如,如果你这样做

List(1, 2) ++ List(3, 4)

您会在 List 的 ScalaDoc 中找到方法 ++。但是,在搜索方法时必须注意一个约定。以冒号 (:) 结尾的方法将 绑定到右侧 而不是左侧。也就是说,虽然上面的方法调用等价于:

List(1, 2).++(List(3, 4))

如果我有,而不是 1 :: List(2, 3),那将相当于:

List(2, 3).::(1)

因此,在查找以冒号结尾的方法时,您需要查看右侧找到的类型。例如,考虑:

1 +: List(2, 3) :+ 4

第一个方法 (+:) 绑定到右侧,并在 List 上找到。第二种方法 (:+) 只是一个普通方法,并且绑定到左侧 -- 再次在 List 上。

语法糖/组合物

所以,这里有一些可能隐藏方法的语法糖:

class Example(arr: Array[Int] = Array.fill(5)(0)) {
  def apply(n: Int) = arr(n)
  def update(n: Int, v: Int) = arr(n) = v
  def a = arr(0); def a_=(v: Int) = arr(0) = v
  def b = arr(1); def b_=(v: Int) = arr(1) = v
  def c = arr(2); def c_=(v: Int) = arr(2) = v
  def d = arr(3); def d_=(v: Int) = arr(3) = v
  def e = arr(4); def e_=(v: Int) = arr(4) = v
  def +(v: Int) = new Example(arr map (_ + v))
  def unapply(n: Int) = if (arr.indices contains n) Some(arr(n)) else None
}

val Ex = new Example // or var for the last example
println(Ex(0))  // calls apply(0)
Ex(0) = 2       // calls update(0, 2)
Ex.b = 3        // calls b_=(3)
// This requires Ex to be a "val"
val Ex(c) = 2   // calls unapply(2) and assigns result to c
// This requires Ex to be a "var"
Ex += 1         // substituted for Ex = Ex + 1

最后一个很有趣,因为任何符号方法都可以通过这种方式组合形成类似赋值的方法。

而且,当然,代码中可以出现多种组合:

(_+_) // An expression, or parameter, that is an anonymous function with
      // two parameters, used exactly where the underscores appear, and
      // which calls the "+" method on the first parameter passing the
      // second parameter as argument.

您的意思是 val c = ex(2) 而不是 val ex(c) = 2
@MikeStay 不,我的意思是val ex(c) = 2
哦,它使用模式匹配语法。谢谢。
也许还应该提到 :/ 和 :\ 非常不直观的运算符。所以 map.foldLeft(initialVal) 与 ( initialVal :/ map ) 相同 - :\ 是 foldRight 。
@DanielC.Sobral 您也许还应该使用 => 添加关于“此别名”的评论,因为直到现在您的描述还没有涵盖它。请参阅 stackoverflow.com/questions/16246531docs.scala-lang.org/tour/self-types.html
P
Peter Mortensen

Scala 和其他语言之间的一个(好的,IMO)区别是它允许您使用几乎任何字符来命名您的方法。

您列举的不是“标点符号”,而是简单明了的方法,因此它们的行为因一个对象而异(尽管有一些约定)。

例如,检查 Scaladoc documentation for List,您将看到您在此处提到的一些方法。

需要记住的一些事项:

大多数情况下,A 运算符+等于 B 组合转换为 A = A 运算符 B,就像 ||= 或 ++= 示例中一样。

以 : 结尾的方法是右结合的,这意味着 A :: B 实际上是 B.::(A)。

您可以通过浏览 Scala 文档找到大部分答案。在此处保留参考会重复工作,并且会很快落后:)


0
0__

您可以根据某些标准将它们首先分组。在这篇文章中,我将只解释下划线字符和右箭头。

_._ 包含句点。 Scala 中的句点始终表示方法调用。因此,在句点的左边是接收者,在句点的右边是消息(方法名称)。现在 _ 在 Scala 中是一个特殊符号。有几篇关于它的帖子,例如 this blog entry all use case。这是一个匿名函数快捷方式,它是一个函数的快捷方式,它接受一个参数并在其上调用方法 _。现在 _ 不是一个有效的方法,所以您肯定会看到 _._1 或类似的东西,即在函数参数上调用方法 _._1_1_22 是提取元组的特定元素的元组方法。例子:

val tup = ("Hallo", 33)
tup._1 // extracts "Hallo"
tup._2 // extracts 33

现在让我们假设函数应用程序快捷方式的用例。给定一个将整数映射到字符串的映射:

val coll = Map(1 -> "Eins", 2 -> "Zwei", 3 -> "Drei")

Wooop,已经出现了另一个奇怪的标点符号。类似于右手箭头的连字符和大于号字符是产生Tuple2的运算符。所以写 (1, "Eins")1 -> "Eins" 的结果没有区别,只是后者更容易阅读,尤其是在像 map 示例这样的元组列表中。 -> 并不神奇,它像其他一些运算符一样可用,因为您在范围内的对象 scala.Predef 中拥有所有 隐式 转换。这里发生的转换是

implicit def any2ArrowAssoc [A] (x: A): ArrowAssoc[A] 

其中 ArrowAssoc 具有创建 Tuple2-> 方法。因此 1 -> "Eins" 是实际的调用 Predef.any2ArrowAssoc(1).->("Eins")。好的。现在回到带有下划线字符的原始问题:

// lets create a sequence from the map by returning the
// values in reverse.
coll.map(_._2.reverse) // yields List(sniE, iewZ, ierD)

此处的下划线缩短了以下等效代码:

coll.map(tup => tup._2.reverse)

请注意,Map 的 map 方法将键和值的元组传递给函数参数。由于我们只对值(字符串)感兴趣,因此我们使用元组上的 _2 方法提取它们。


+1 我在尝试理解 -> 方法时遇到了麻烦,但您的句子“所以写 (1, "Eins")1 -> "Eins" 的结果没有区别”帮助我理解了语法及其用法。
仅供参考,您的博客条目链接已失效
P
Peter Mortensen

作为 Daniel 和 0__ 出色答案的补充,我不得不说 Scala 理解某些符号的 Unicode 类似物,所以不是

for (n <- 1 to 10) n % 2 match {
  case 0 => println("even")
  case 1 => println("odd")
}

一个人可以写

for (n ← 1 to 10) n % 2 match {
  case 0 ⇒ println("even")
  case 1 ⇒ println("odd")
}

A
Alex M.

关于 ::,还有另一个 Stackoverflow 条目涵盖了 :: 情况。简而言之,它用于通过“consing”一个头元素和一个尾列表来构造Lists。它既是一个 class,它代表一个 cons'ed 列表,也可以用作提取器,但最常见的是它是一个列表上的 方法。正如 Pablo Fernandez 指出的那样,由于它以冒号结尾,因此它是右关联,这意味着方法调用的接收者在右侧,而参数在运算符的左侧。这样你就可以优雅地将 consing 表达为 prepending 一个新的 head 元素到现有列表:

val x = 2 :: 3 :: Nil  // same result as List(2, 3)
val y = 1 :: x         // yields List(1, 2, 3)

这相当于

val x = Nil.::(3).::(2) // successively prepend 3 and 2 to an empty list
val y = x.::(1)         // then prepend 1

作为提取器对象的使用如下:

def extract(l: List[Int]) = l match {
   case Nil          => "empty"
   case head :: Nil  => "exactly one element (" + head + ")"
   case head :: tail => "more than one element"
}

extract(Nil)          // yields "empty"
extract(List(1))      // yields "exactly one element (1)"
extract(List(2, 3))   // yields "more than one element"

这在这里看起来像一个运算符,但它实际上只是另一种(更易读)的写作方式

def extract2(l: List[Int]) = l match {
   case Nil            => "empty"
   case ::(head, Nil)  => "exactly one element (" + head + ")"
   case ::(head, tail) => "more than one element"
}

您可以在 this post 中阅读有关提取器的更多信息。


0
0__

<= 就像您“阅读”它一样:“小于或等于”。所以它是一个数学运算符,在 <(小于?)、>(大于?)、==(等于?)、!=(不等于?)、{1 }(小于或等于?)和 >=(大于或等于?)。

这不能混淆=>,它是一种右箭头,用于将参数列表与函数体分开,并将匹配发生时执行的主体中的模式匹配(case 块)中的测试条件。你可以在我之前的两个答案中看到这个例子。一、函数使用:

coll.map(tup => tup._2.reverse)

由于省略了类型,因此已经缩写了。跟随功能将是

// function arguments         function body
(tup: Tuple2[Int, String]) => tup._2.reverse

和模式匹配使用:

def extract2(l: List[Int]) = l match {
   // if l matches Nil    return "empty"
   case Nil            => "empty"
   // etc.
   case ::(head, Nil)  => "exactly one element (" + head + ")"
   // etc.
   case ::(head, tail) => "more than one element"
}

为了避免这种混淆,我决定开始对右双箭头 (\U21D2)、单右“映射”箭头 (\U2192) 和左单“入”箭头 (\U2190) 使用 unicode 字符。 Scala 支持这一点,但我有点怀疑,直到我尝试了一段时间。只需查看如何将这些代码点绑定到系统上的方便组合键即可。在 OS X 上真的很容易。
A
Adowrath

只是添加到其他优秀的答案。 Scala 提供了两个经常受到批评的符号运算符,/: (foldLeft) 和 :\ (foldRight) 运算符,第一个是右结合运算符。所以下面三个语句是等价的:

( 1 to 100 ).foldLeft( 0, _+_ )
( 1 to 100 )./:( 0 )( _+_ )
( 0 /: ( 1 to 100 ) )( _+_ )

就像这三个:

( 1 to 100 ).foldRight( 0, _+_ )
( 1 to 100 ).:\( 0 )( _+_ )
( ( 1 to 100 ) :\ 0 )( _+_ )

n
nairbv

我认为现代 IDE 对于理解大型 Scala 项目至关重要。由于这些运算符也是方法,因此在 intellij idea 中我只需 control-click 或 control-b 进入定义。

您可以控制并单击右键进入 cons 运算符 (::),然后在 scala javadoc 中显示“在此列表的开头添加一个元素”。在用户定义的运算符中,这变得更加关键,因为它们可以在难以找到的隐式中定义……您的 IDE 知道隐式的定义位置。


0
0__

Scala 继承了 Java's arithmetic operators 的大部分内容。这包括按位或 |(单管道字符)、按位与 &、按位排他或 ^,以及逻辑(布尔)或 ||(两个管道字符)和逻辑与&&。有趣的是,您可以在 boolean 上使用单字符运算符,因此 java'ish 逻辑运算符是完全多余的:

true && true   // valid
true & true    // valid as well

3 & 4          // bitwise-and (011 & 100 yields 000)
3 && 4         // not valid

正如另一篇文章中所指出的,以等号 = 结尾的调用通过重新分配来解决(如果不存在具有该名称的方法!):

var x = 3
x += 1         // `+=` is not a method in `int`, Scala makes it `x = x + 1`

这种“双重检查”可以轻松地将可变集合交换为不可变集合:

val m = collection.mutable.Set("Hallo")   // `m` a val, but holds mutable coll
var i = collection.immutable.Set("Hallo") // `i` is a var, but holds immutable coll

m += "Welt" // destructive call m.+=("Welt")
i += "Welt" // re-assignment i = i + "Welt" (creates a new immutable Set)

PS 在布尔值上使用单字符和双字符运算符是有区别的——前者是急切的(所有术语都被评估),如果结果布尔值已知,后者会提前终止:true | { println( "Icke" ); true } ⇒ 打印! true || { println( "Icke" ); true }打印!
G
Geoff Davids

哦,所以你想要一个详尽的答案?这是一个有趣的、希望是完整的、相当冗长的列表:)

http://jim-mcbeath.blogspot.com/2008/12/scala-operator-cheat-sheet.html

(免责声明 - 该帖子写于 2008 年,所以可能有点过时)

!! AbstractActor
!! Actor // Sends msg to this actor and immediately ...
!! Proxy
! Actor // Sends msg to this actor (asynchronous).
! Channel // Sends a message to this Channel.
! OutputChannel // Sends msg to this ...
! Proxy // Sends msg to this ...
!= Any // o != arg0 is the same as !(o == (arg0)).
!= AnyRef
!= Boolean
!= Byte
!= Char
!= Double
!= Float
!= Int
!= Long
!= Short
!? AbstractActor
!? Actor // Sends msg to this actor and awaits reply ...
!? Channel // Sends a message to this Channel and ...
!? Proxy
% BigInt // Remainder of BigInts
% Byte
% Char
% Double
% Float
% Int
% Long
% Short
% Elem // Returns a new element with updated attributes, resolving namespace uris from this element's scope. ...
&&& Parsers.Parser
&& Boolean
&+ NodeBuffer // Append given object to this buffer, returns reference on this NodeBuffer ...
& BigInt // Bitwise and of BigInts
& Boolean
& Byte
& Char
& Enumeration.Set32 // Equivalent to * for bit sets. ...
& Enumeration.Set64 // Equivalent to * for bit sets. ...
& Enumeration.SetXX // Equivalent to * for bit sets. ...
& Int
& Long
& Short
&~ BigInt // Bitwise and-not of BigInts. Returns a BigInt whose value is (this & ~that).
&~ Enumeration.Set32 // Equivalent to - for bit sets. ...
&~ Enumeration.Set64 // Equivalent to - for bit sets. ...
&~ Enumeration.SetXX // Equivalent to - for bit sets. ...
>>> Byte
>>> Char
>>> Int
>>> Long
>>> Short
>> BigInt // (Signed) rightshift of BigInt
>> Byte
>> Char
>> Int
>> Long
>> Short
>> Parsers.Parser // Returns into(fq)
>> Parsers.Parser // Returns into(fq)
> BigDecimal // Greater-than comparison of BigDecimals
> BigInt // Greater-than comparison of BigInts
> Byte
> Char
> Double
> Float
> Int
> Long
> Ordered
> PartiallyOrdered
> Short
>= BigDecimal // Greater-than-or-equals comparison of BigDecimals
>= BigInt // Greater-than-or-equals comparison of BigInts
>= Byte
>= Char
>= Double
>= Float
>= Int
>= Long
>= Ordered
>= PartiallyOrdered
>= Short
<< BigInt // Leftshift of BigInt
<< Byte
<< Char
<< Int
<< Long
<< Short
<< Buffer // Send a message to this scriptable object.
<< BufferProxy // Send a message to this scriptable object.
<< Map // Send a message to this scriptable object.
<< MapProxy // Send a message to this scriptable object.
<< Scriptable // Send a message to this scriptable object.
<< Set // Send a message to this scriptable object.
<< SetProxy // Send a message to this scriptable object.
<< SynchronizedBuffer // Send a message to this scriptable object.
<< SynchronizedMap // Send a message to this scriptable object.
<< SynchronizedSet // Send a message to this scriptable object.
< BigDecimal // Less-than of BigDecimals
< BigInt // Less-than of BigInts
< Byte
< Char
< Double
< Float
< Int
< Long
< Ordered
< PartiallyOrdered
< Short
< OffsetPosition // Compare this position to another, by first comparing their line numbers, ...
< Position // Compare this position to another, by first comparing their line numbers, ...
<= BigDecimal // Less-than-or-equals comparison of BigDecimals
<= BigInt // Less-than-or-equals comparison of BigInts
<= Byte
<= Char
<= Double
<= Float
<= Int
<= Long
<= Ordered
<= PartiallyOrdered
<= Short
<~ Parsers.Parser // A parser combinator for sequential composition which keeps only the left result
** Enumeration.SetXX
** Set // Intersect. It computes an intersection with set that. ...
** Set // This method is an alias for intersect. ...
* BigDecimal // Multiplication of BigDecimals
* BigInt // Multiplication of BigInts
* Byte
* Char
* Double
* Float
* Int
* Long
* Short
* Set
* RichString // return n times the current string
* Parsers.Parser // Returns a parser that repeatedly parses what this parser parses, interleaved with the `sep' parser. ...
* Parsers.Parser // Returns a parser that repeatedly parses what this parser parses
* Parsers.Parser // Returns a parser that repeatedly parses what this parser parses, interleaved with the `sep' parser. ...
* Parsers.Parser // Returns a parser that repeatedly parses what this parser parses, interleaved with the `sep' parser.
* Parsers.Parser // Returns a parser that repeatedly parses what this parser parses
++: ArrayBuffer // Prepends a number of elements provided by an iterable object ...
++: Buffer // Prepends a number of elements provided by an iterable object ...
++: BufferProxy // Prepends a number of elements provided by an iterable object ...
++: SynchronizedBuffer // Prepends a number of elements provided by an iterable object ...
++ Array // Returns an array consisting of all elements of this array followed ...
++ Enumeration.SetXX
++ Iterable // Appends two iterable objects.
++ IterableProxy // Appends two iterable objects.
++ Iterator // Returns a new iterator that first yields the elements of this ...
++ List // Appends two list objects.
++ RandomAccessSeq // Appends two iterable objects.
++ RandomAccessSeqProxy // Appends two iterable objects.
++ Seq // Appends two iterable objects.
++ SeqProxy // Appends two iterable objects.
++ IntMap // Add a sequence of key/value pairs to this map.
++ LongMap // Add a sequence of key/value pairs to this map.
++ Map // Add a sequence of key/value pairs to this map.
++ Set // Add all the elements provided by an iterator ...
++ Set // Add all the elements provided by an iterator to the set.
++ SortedMap // Add a sequence of key/value pairs to this map.
++ SortedSet // Add all the elements provided by an iterator ...
++ Stack // Push all elements provided by the given iterable object onto ...
++ Stack // Push all elements provided by the given iterator object onto ...
++ TreeHashMap
++ TreeHashMap // Add a sequence of key/value pairs to this map.
++ Collection // Operator shortcut for addAll.
++ Set // Operator shortcut for addAll.
++ ArrayBuffer // Appends two iterable objects.
++ Buffer // Appends a number of elements provided by an iterable object ...
++ Buffer // Appends a number of elements provided by an iterator ...
++ Buffer // Appends two iterable objects.
++ BufferProxy // Appends a number of elements provided by an iterable object ...
++ Map // Add a sequence of key/value pairs to this map.
++ MapProxy // Add a sequence of key/value pairs to this map.
++ PriorityQueue
++ Set // Add all the elements provided by an iterator ...
++ SynchronizedBuffer // Appends a number of elements provided by an iterable object ...
++ RichString // Appends two iterable objects.
++ RichStringBuilder // Appends a number of elements provided by an iterable object ...
++ RichStringBuilder // Appends two iterable objects.
++= Map // Add a sequence of key/value pairs to this map.
++= MapWrapper // Add a sequence of key/value pairs to this map.
++= ArrayBuffer // Appends a number of elements in an array
++= ArrayBuffer // Appends a number of elements provided by an iterable object ...
++= ArrayStack // Pushes all the provided elements onto the stack.
++= Buffer // Appends a number of elements in an array
++= Buffer // Appends a number of elements provided by an iterable object ...
++= Buffer // Appends a number of elements provided by an iterator
++= BufferProxy // Appends a number of elements provided by an iterable object ...
++= Map // Add a sequence of key/value pairs to this map.
++= MapProxy // Add a sequence of key/value pairs to this map.
++= PriorityQueue // Adds all elements provided by an Iterable object ...
++= PriorityQueue // Adds all elements provided by an iterator into the priority queue.
++= PriorityQueueProxy // Adds all elements provided by an Iterable object ...
++= PriorityQueueProxy // Adds all elements provided by an iterator into the priority queue.
++= Queue // Adds all elements provided by an Iterable object ...
++= Queue // Adds all elements provided by an iterator ...
++= QueueProxy // Adds all elements provided by an Iterable object ...
++= QueueProxy // Adds all elements provided by an iterator ...
++= Set // Add all the elements provided by an iterator ...
++= SetProxy // Add all the elements provided by an iterator ...
++= Stack // Pushes all elements provided by an Iterable object ...
++= Stack // Pushes all elements provided by an iterator ...
++= StackProxy // Pushes all elements provided by an Iterable object ...
++= StackProxy // Pushes all elements provided by an iterator ...
++= SynchronizedBuffer // Appends a number of elements provided by an iterable object ...
++= SynchronizedMap // Add a sequence of key/value pairs to this map.
++= SynchronizedPriorityQueue // Adds all elements provided by an Iterable object ...
++= SynchronizedPriorityQueue // Adds all elements provided by an iterator into the priority queue.
++= SynchronizedQueue // Adds all elements provided by an Iterable object ...
++= SynchronizedQueue // Adds all elements provided by an iterator ...
++= SynchronizedSet // Add all the elements provided by an iterator ...
++= SynchronizedStack // Pushes all elements provided by an Iterable object ...
++= SynchronizedStack // Pushes all elements provided by an iterator ...
++= RichStringBuilder // Appends a number of elements provided by an iterable object ...
+: ArrayBuffer // Prepends a single element to this buffer and return ...
+: Buffer // Prepend a single element to this buffer and return ...
+: BufferProxy // Prepend a single element to this buffer and return ...
+: ListBuffer // Prepends a single element to this buffer. It takes constant ...
+: ObservableBuffer // Prepend a single element to this buffer and return ...
+: SynchronizedBuffer // Prepend a single element to this buffer and return ...
+: RichStringBuilder // Prepend a single element to this buffer and return ...
+: BufferWrapper // Prepend a single element to this buffer and return ...
+: RefBuffer // Prepend a single element to this buffer and return ...
+ BigDecimal // Addition of BigDecimals
+ BigInt // Addition of BigInts
+ Byte
+ Char
+ Double
+ Enumeration.SetXX // Create a new set with an additional element.
+ Float
+ Int
+ List
+ Long
+ Short
+ EmptySet // Create a new set with an additional element.
+ HashSet // Create a new set with an additional element.
+ ListSet.Node // This method creates a new set with an additional element.
+ ListSet // This method creates a new set with an additional element.
+ Map
+ Map // Add a key/value pair to this map.
+ Map // Add two or more key/value pairs to this map.
+ Queue // Creates a new queue with element added at the end ...
+ Queue // Returns a new queue with all all elements provided by ...
+ Set // Add two or more elements to this set.
+ Set // Create a new set with an additional element.
+ Set1 // Create a new set with an additional element.
+ Set2 // Create a new set with an additional element.
+ Set3 // Create a new set with an additional element.
+ Set4 // Create a new set with an additional element.
+ SortedMap // Add a key/value pair to this map.
+ SortedMap // Add two or more key/value pairs to this map.
+ SortedSet // Create a new set with an additional element.
+ Stack // Push all elements provided by the given iterable object onto ...
+ Stack // Push an element on the stack.
+ TreeSet // A new TreeSet with the entry added is returned,
+ Buffer // adds "a" from the collection. Useful for chaining.
+ Collection // adds "a" from the collection. Useful for chaining.
+ Map // Add a key/value pair to this map.
+ Set // adds "a" from the collection. Useful for chaining.
+ Buffer // Append a single element to this buffer and return ...
+ BufferProxy // Append a single element to this buffer and return ...
+ Map // Add a key/value pair to this map.
+ Map // Add two or more key/value pairs to this map.
+ MapProxy // Add a key/value pair to this map.
+ MapProxy // Add two or more key/value pairs to this map.
+ ObservableBuffer // Append a single element to this buffer and return ...
+ PriorityQueue
+ Set // Add a new element to the set.
+ Set // Add two or more elements to this set.
+ SynchronizedBuffer // Append a single element to this buffer and return ...
+ Parsers.Parser // Returns a parser that repeatedly (at least once) parses what this parser parses.
+ Parsers.Parser // Returns a parser that repeatedly (at least once) parses what this parser parses.
+= Collection // adds "a" from the collection.
+= Map // Add a key/value pair to this map.
+= ArrayBuffer // Appends a single element to this buffer and returns ...
+= ArrayStack // Alias for push.
+= BitSet // Sets i-th bit to true. ...
+= Buffer // Append a single element to this buffer.
+= BufferProxy // Append a single element to this buffer.
+= HashSet // Add a new element to the set.
+= ImmutableSetAdaptor // Add a new element to the set.
+= JavaSetAdaptor // Add a new element to the set.
+= LinkedHashSet // Add a new element to the set.
+= ListBuffer // Appends a single element to this buffer. It takes constant ...
+= Map // Add a key/value pair to this map.
+= Map // Add two or more key/value pairs to this map.
+= Map // This method defines syntactic sugar for adding or modifying ...
+= MapProxy // Add a key/value pair to this map.
+= MapProxy // Add two or more key/value pairs to this map.
+= ObservableSet // Add a new element to the set.
+= PriorityQueue // Add two or more elements to this set.
+= PriorityQueue // Inserts a single element into the priority queue.
+= PriorityQueueProxy // Inserts a single element into the priority queue.
+= Queue // Inserts a single element at the end of the queue.
+= QueueProxy // Inserts a single element at the end of the queue.
+= Set // Add a new element to the set.
+= Set // Add two or more elements to this set.
+= SetProxy // Add a new element to the set.
+= Stack // Pushes a single element on top of the stack.
+= StackProxy // Pushes a single element on top of the stack.
+= SynchronizedBuffer // Append a single element to this buffer.
+= SynchronizedMap // Add a key/value pair to this map.
+= SynchronizedMap // Add two or more key/value pairs to this map.
+= SynchronizedPriorityQueue // Inserts a single element into the priority queue.
+= SynchronizedQueue // Inserts a single element at the end of the queue.
+= SynchronizedSet // Add a new element to the set.
+= SynchronizedStack // Pushes a single element on top of the stack.
+= RichStringBuilder // Append a single element to this buffer.
+= Reactions // Add a reaction.
+= RefBuffer // Append a single element to this buffer.
+= CachedFileStorage // adds a node, setting this.dirty to true as a side effect
+= IndexedStorage // adds a node, setting this.dirty to true as a side effect
+= SetStorage // adds a node, setting this.dirty to true as a side effect
-> Map.MapTo
-> Map.MapTo
-- List // Computes the difference between this list and the given list ...
-- Map // Remove a sequence of keys from this map
-- Set // Remove all the elements provided by an iterator ...
-- SortedMap // Remove a sequence of keys from this map
-- MutableIterable // Operator shortcut for removeAll.
-- Set // Operator shortcut for removeAll.
-- Map // Remove a sequence of keys from this map
-- MapProxy // Remove a sequence of keys from this map
-- Set // Remove all the elements provided by an iterator ...
--= Map // Remove a sequence of keys from this map
--= MapProxy // Remove a sequence of keys from this map
--= Set // Remove all the elements provided by an iterator ...
--= SetProxy // Remove all the elements provided by an iterator ...
--= SynchronizedMap // Remove a sequence of keys from this map
--= SynchronizedSet // Remove all the elements provided by an iterator ...
- BigDecimal // Subtraction of BigDecimals
- BigInt // Subtraction of BigInts
- Byte
- Char
- Double
- Enumeration.SetXX // Remove a single element from a set.
- Float
- Int
- List // Computes the difference between this list and the given object ...
- Long
- Short
- EmptyMap // Remove a key from this map
- EmptySet // Remove a single element from a set.
- HashMap // Remove a key from this map
- HashSet // Remove a single element from a set.
- IntMap // Remove a key from this map
- ListMap.Node // Creates a new mapping without the given key. ...
- ListMap // This creates a new mapping without the given key. ...
- ListSet.Node // - can be used to remove a single element from ...
- ListSet // - can be used to remove a single element from ...
- LongMap // Remove a key from this map
- Map // Remove a key from this map
- Map // Remove two or more keys from this map
- Map1 // Remove a key from this map
- Map2 // Remove a key from this map
- Map3 // Remove a key from this map
- Map4 // Remove a key from this map
- Set // Remove a single element from a set.
- Set // Remove two or more elements from this set.
- Set1 // Remove a single element from a set.
- Set2 // Remove a single element from a set.
- Set3 // Remove a single element from a set.
- Set4 // Remove a single element from a set.
- SortedMap // Remove a key from this map
- SortedMap // Remove two or more keys from this map
- TreeHashMap // Remove a key from this map
- TreeMap // Remove a key from this map
- TreeSet // Remove a single element from a set.
- UnbalancedTreeMap.Node // Remove a key from this map
- UnbalancedTreeMap // Remove a key from this map
- Map // Remove a key from this map
- MutableIterable
- Set
- ListBuffer // Removes a single element from the buffer and return ...
- Map // Remove a key from this map
- Map // Remove two or more keys from this map
- MapProxy // Remove a key from this map
- MapProxy // Remove two or more keys from this map
- Set // Remove a new element from the set.
- Set // Remove two or more elements from this set.
-= Buffer // removes "a" from the collection.
-= Collection // removes "a" from the collection.
-= Map // Remove a key from this map, noop if key is not present.
-= BitSet // Clears the i-th bit.
-= Buffer // Removes a single element from this buffer, at its first occurrence. ...
-= HashMap // Remove a key from this map, noop if key is not present.
-= HashSet // Removes a single element from a set.
-= ImmutableMapAdaptor // Remove a key from this map, noop if key is not present.
-= ImmutableSetAdaptor // Removes a single element from a set.
-= JavaMapAdaptor // Remove a key from this map, noop if key is not present.
-= JavaSetAdaptor // Removes a single element from a set.
-= LinkedHashMap // Remove a key from this map, noop if key is not present.
-= LinkedHashSet // Removes a single element from a set.
-= ListBuffer // Remove a single element from this buffer. It takes linear time ...
-= Map // Remove a key from this map, noop if key is not present.
-= Map // Remove two or more keys from this map
-= MapProxy // Remove a key from this map, noop if key is not present.
-= MapProxy // Remove two or more keys from this map
-= ObservableMap // Remove a key from this map, noop if key is not present.
-= ObservableSet // Removes a single element from a set.
-= OpenHashMap // Remove a key from this map, noop if key is not present.
-= Set // Remove two or more elements from this set.
-= Set // Removes a single element from a set.
-= SetProxy // Removes a single element from a set.
-= SynchronizedMap // Remove a key from this map, noop if key is not present.
-= SynchronizedMap // Remove two or more keys from this map
-= SynchronizedSet // Removes a single element from a set.
-= Reactions // Remove the given reaction.
-= CachedFileStorage // removes a tree, setting this.dirty to true as a side effect
-= IndexedStorage // removes a tree, setting this.dirty to true as a side effect
/% BigInt // Returns a pair of two BigInts containing (this / that) and (this % that).
/: Iterable // Similar to foldLeft but can be used as ...
/: IterableProxy // Similar to foldLeft but can be used as ...
/: Iterator // Similar to foldLeft but can be used as ...
/ BigDecimal // Division of BigDecimals
/ BigInt // Division of BigInts
/ Byte
/ Char
/ Double
/ Float
/ Int
/ Long
/ Short
:/: Document
::: List
:: List
:: Document
:\ Iterable // An alias for foldRight. ...
:\ IterableProxy // An alias for foldRight. ...
:\ Iterator // An alias for foldRight. ...
== Any // o == arg0 is the same as o.equals(arg0).
== AnyRef // o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).
== Boolean
== Byte
== Char
== Double
== Float
== Int
== Long
== Short
? Actor // Receives the next message from this actor's mailbox.
? Channel // Receives the next message from this Channel.
? InputChannel // Receives the next message from this Channel.
? Parsers.Parser // Returns a parser that optionally parses what this parser parses.
? Parsers.Parser // Returns a parser that optionally parses what this parser parses.
\ NodeSeq // Projection function. Similar to XPath, use this \ "foo"
\\ NodeSeq // projection function. Similar to XPath, use this \\ 'foo
^ BigInt // Bitwise exclusive-or of BigInts
^ Boolean
^ Byte
^ Char
^ Int
^ Long
^ Short
^? Parsers.Parser // A parser combinator for partial function application
^? Parsers.Parser // A parser combinator for partial function application
^^ Parsers.Parser // A parser combinator for function application
^^ Parsers.Parser // A parser combinator for function application
^^ Parsers.UnitParser // A parser combinator for function application
^^^ Parsers.Parser
| BigInt // Bitwise or of BigInts
| Boolean
| Byte
| Char
| Enumeration.Set32 // Equivalent to ++ for bit sets. Returns a set ...
| Enumeration.Set32 // Equivalent to + for bit sets. Returns a set ...
| Enumeration.Set64 // Equivalent to ++ for bit sets. Returns a set ...
| Enumeration.Set64 // Equivalent to + for bit sets. Returns a set ...
| Enumeration.SetXX // Equivalent to ++ for bit sets. Returns a set ...
| Enumeration.SetXX // Equivalent to + for bit sets. Returns a set ...
| Int
| Long
| Short
| Parsers.Parser // A parser combinator for alternative composition
| Parsers.Parser // A parser combinator for alternative composition
| Parsers.UnitParser // A parser combinator for alternative composition
|| Boolean
||| Parsers.Parser
||| Parsers.Parser // A parser combinator for alternative with longest match composition
||| Parsers.Parser // A parser combinator for alternative with longest match composition
||| Parsers.UnitParser // A parser combinator for alternative with longest match composition
~! Parsers.Parser // A parser combinator for non-back-tracking sequential composition
~! Parsers.Parser // A parser combinator for non-back-tracking sequential composition with a unit-parser
~! Parsers.Parser // A parser combinator for non-back-tracking sequential composition
~! Parsers.UnitParser // A parser combinator for non-back-tracking sequential composition with a unit-parser
~! Parsers.UnitParser // A parser combinator for non-back-tracking sequential composition
~> Parsers.Parser // A parser combinator for sequential composition which keeps only the right result
~ BigInt // Returns the bitwise complement of this BigNum
~ Parsers.OnceParser // A parser combinator for sequential composition
~ Parsers.Parser // A parser combinator for sequential composition
~ Parsers
~ Parsers.OnceParser // A parser combinator for sequential composition with a unit-parser
~ Parsers.OnceParser // A parser combinator for sequential composition
~ Parsers.Parser // A parser combinator for sequential composition with a unit-parser
~ Parsers.Parser // A parser combinator for sequential composition
~ Parsers.UnitOnceParser // A parser combinator for sequential composition with a unit-parser
~ Parsers.UnitOnceParser // A parser combinator for sequential composition
~ Parsers.UnitParser // A parser combinator for sequential composition with a unit-parser
~ Parsers.UnitParser // A parser combinator for sequential composition
unary_! Boolean
unary_+ Byte
unary_+ Char
unary_+ Double
unary_+ Float
unary_+ Int
unary_+ Long
unary_+ Short
unary_- BigDecimal // Returns a BigDecimal whose value is the negation of this BigDecimal
unary_- BigInt // Returns a BigInt whose value is the negation of this BigInt
unary_- Byte
unary_- Char
unary_- Double
unary_- Float
unary_- Int
unary_- Long
unary_- Short
unary_~ Byte
unary_~ Char
unary_~ Int
unary_~ Long
unary_~ Short

s
sparker

这里有很好的详尽答案。

对我来说,一个关键点是其中有 2 类

op提到的符号是scala sdk中的函数名。在 scala 中,编写具有这些字符(包括 unicode 字符)名称的函数是合法的。尝试从其他答案中已经提到的 sdk 中提及所有这些将是一个很好的长列表

还有一些符号不是函数名称,而是语言语法本身的一部分,例如 =>_ 或运算符,例如 &&|| 等。


l
lawazoni

?=> (至少在 scala 3 中)用于定义一个函数,该函数将隐含地接受参数,因为我在上一课 coursera 课程 2(设计)中从 Odersky 理解它,订阅者/观察者模式编写信号 frp 框架,你能请添加这个以便尽快删除此帖子

>   def apply[T](expr: Caller ?=> T): Signal[T] =
new AbstractSignal[T]:
  protected val eval = expr(using _)
  computeValue()