Skip to content

Commit 0234fa4

Browse files
authored
FAQ: minor improvements to functions vs methods (#3068)
1 parent cfa4a0d commit 0234fa4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

_overviews/FAQ/index.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,22 @@ differ from a function value such as:
248248

249249
val square: Int => Int = x => x * x
250250

251-
For Scala 2, there is a [complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404)
251+
For **Scala 2**, there is a [complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404)
252252
and a [summary with practical differences](https://tpolecat.github.io/2014/06/09/methods-functions.html).
253253

254-
Note that in **Scala 3** the differences are fewer;
255-
for example, they will be able to
256-
[accept implicit parameters]({{ site.scala3ref }}/contextual/context-functions.html)
257-
as well as [type parameters]({{ site.scala3ref }}/new-types/polymorphic-function-types.html).
258-
259-
Nevertheless, it is still recommended to use methods most of the time,
260-
unless you absolutely need a function. And, thanks to
261-
[eta-expansion](https://stackoverflow.com/questions/39445018/what-is-the-eta-expansion-in-scala)
262-
you rarely would need to define a function rather than a method.
254+
In **Scala 3**, the differences are fewer.
255+
[Context functions]({{ site.scala3ref }}/contextual/context-functions.html)
256+
accept given parameters and
257+
[polymorphic functions]({{ site.scala3ref }}/new-types/polymorphic-function-types.html)
258+
have type parameters.
259+
260+
It's standard to use methods most of the time,
261+
except when function value is actually needed.
262+
[Eta-expansion](https://stackoverflow.com/questions/39445018/what-is-the-eta-expansion-in-scala),
263+
converts methods to functions when needed.
264+
For example, a method such as `map` expects a function,
265+
but even if you `def square` as shown above, you can
266+
still `xs.map(square)`.
263267

264268
### What's the difference between types and classes?
265269

0 commit comments

Comments
 (0)