Scala 的“魔法"列表职能 [英] List of Scala's "magic" functions

查看:34
本文介绍了Scala 的“魔法"列表职能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到 Scala 的神奇"函数列表,例如 applyunapplyupdate+= 等?

Where can I find a list of Scala's "magic" functions, such as apply, unapply, update, +=, etc.?

魔术函数是指编译器的某些语法糖使用的函数,例如

By magic-functions I mean functions which are used by some syntactic sugar of the compiler, for example

o.update(x,y) <=> o(x) = y

我在谷歌上搜索了 scala magicfunctions 的同义词的一些组合,但我没有找到任何东西.

I googled for some combination of scala magic and synonyms of functions, but I didn't find anything.

我对标准库中魔术函数的用法不感兴趣,但其中存在魔术函数.

I'm not interested with the usage of magic functions in the standard library, but in which magic functions exists.

推荐答案

据我所知:

getter/setter 相关:

Getters/setters related:

apply
update
identifier_=

模式匹配:

unapply
unapplySeq

理解:

map
flatMap
filter
withFilter
foreach

前缀运算符:

unary_+
unary_-
unary_!
unary_~

除此之外,任何从 A 到 B 的隐式.Scala 也会将 A = B 转换为 A = A B,如果前面的操作符没有定义,op"不是字母数字,=也不是!===<=>=.

Beyond that, any implicit from A to B. Scala will also convert A <op>= B into A = A <op> B, if the former operator isn't defined, "op" is not alphanumeric, and <op>= isn't !=, ==, <= or >=.

而且我不相信任何地方都列出了 Scala 的所有语法糖.

And I don't believe there's any single place where all of Scala's syntactic sugars are listed.

这篇关于Scala 的“魔法"列表职能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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