From 562b7443cd16ce6014d6e484d0233aab1cb31746 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Fri, 6 Sep 2024 13:53:25 +0200 Subject: [PATCH 1/2] FAQ: minor improvements to functions vs methods --- _overviews/FAQ/index.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/_overviews/FAQ/index.md b/_overviews/FAQ/index.md index 7d3966986..46bcc15c4 100644 --- a/_overviews/FAQ/index.md +++ b/_overviews/FAQ/index.md @@ -244,18 +244,19 @@ differ from a function value such as: val square: Int => Int = x => x * x -For Scala 2, there is a [complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404) +For **Scala 2**, there is a [complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404) and a [summary with practical differences](https://tpolecat.github.io/2014/06/09/methods-functions.html). -Note that in **Scala 3** the differences are fewer; -for example, they will be able to -[accept implicit parameters]({{ site.scala3ref }}/contextual/context-functions.html) -as well as [type parameters]({{ site.scala3ref }}/new-types/polymorphic-function-types.html). +In **Scala 3**, the differences are fewer. +[Context functions]({{ site.scala3ref }}/contextual/context-functions.html) +accept given parameters and +[polymorphic functions]({{ site.scala3ref }}/new-types/polymorphic-function-types.html) +have type parameters. -Nevertheless, it is still recommended to use methods most of the time, -unless you absolutely need a function. And, thanks to -[eta-expansion](https://stackoverflow.com/questions/39445018/what-is-the-eta-expansion-in-scala) -you rarely would need to define a function rather than a method. +Most code uses methods most of the time, +unless a function value is actually needed. With +[eta-expansion](https://stackoverflow.com/questions/39445018/what-is-the-eta-expansion-in-scala), +a method can be converted as a function when needed. ### What's the difference between types and classes? From 633ed9b5d65beac60060e448092c2b7c53cb451d Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Sat, 19 Oct 2024 13:33:52 -0700 Subject: [PATCH 2/2] respond to review feedback --- _overviews/FAQ/index.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/_overviews/FAQ/index.md b/_overviews/FAQ/index.md index 46bcc15c4..2ac74fbcb 100644 --- a/_overviews/FAQ/index.md +++ b/_overviews/FAQ/index.md @@ -253,10 +253,13 @@ accept given parameters and [polymorphic functions]({{ site.scala3ref }}/new-types/polymorphic-function-types.html) have type parameters. -Most code uses methods most of the time, -unless a function value is actually needed. With -[eta-expansion](https://stackoverflow.com/questions/39445018/what-is-the-eta-expansion-in-scala), -a method can be converted as a function when needed. +It's standard to use methods most of the time, +except when function value is actually needed. +[Eta-expansion](https://stackoverflow.com/questions/39445018/what-is-the-eta-expansion-in-scala), +converts methods to functions when needed. +For example, a method such as `map` expects a function, +but even if you `def square` as shown above, you can +still `xs.map(square)`. ### What's the difference between types and classes?