Skip to content

Commit

Permalink
spec companion objects extending apply template
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnhoekstra committed Dec 4, 2023
1 parent e63be01 commit c51e715
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spec/05-classes-and-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,11 @@ a `val` or `var` modifier. Hence, an accessor
definition for the parameter is [generated](#class-definitions).

A case class definition of `´c´[´\mathit{tps}\,´](´\mathit{ps}_1\,´)´\ldots´(´\mathit{ps}_n´)` with type
parameters ´\mathit{tps}´ and value parameters ´\mathit{ps}´ implies
parameters ´\mathit{tps}´ and value parameters ´\mathit{ps}´ with type ascriptions ´\mathit{pts}´ implies
the definition of a companion object, which serves as an [extractor object](08-pattern-matching.html#extractor-patterns). It has the following shape:

```scala
object ´c´ {
object ´c´ extends Function´\mathit{n}\,´[´\mathit{pt}_1\,\ldots\,\mathit{pt}_n´\,´c´[´\mathit{tps}\,´]]{
def apply\mathit{tps}\,´](´\mathit{ps}_1\,´)´\ldots´(´\mathit{ps}_n´): ´c´[´\mathit{tps}\,´] = new ´c´[´\mathit{Ts}\,´](´\mathit{xs}_1\,´)´\ldots´(´\mathit{xs}_n´)
def unapply\mathit{tps}\,´](´x´: ´c´[´\mathit{tps}\,´]) =
if (x eq null) scala.None
Expand All @@ -888,6 +888,8 @@ If the object ´c´ already has a [matching](#definition-matching)
`apply` (or `unapply`) member, no new definition is added.
The definition of `apply` is omitted if class ´c´ is `abstract`.

It will not be modified to extend Function if the existing definition doesn't extend it.

If the case class definition contains an empty value parameter list, the
`unapply` method returns a `Boolean` instead of an `Option` type and
is defined as follows:
Expand Down

0 comments on commit c51e715

Please sign in to comment.