Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 views
in Technique[技术] by (71.8m points)

syntax - List of Scala's "magic" functions

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I know:

Getters/setters related:

apply
update
identifier_=

Pattern matching:

unapply
unapplySeq

For-comprehensions:

map
flatMap
filter
withFilter
foreach

Prefixed operators:

unary_+
unary_-
unary_!
unary_~

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 >=.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...