Skip to content

Is PartialFunction a SAM? #504

Closed
Closed
@DarkDimius

Description

@DarkDimius

In order to implement a PartialFunction one needs to define both

def isDefinedAt(x: T)
def apply(x: T)

so there are two abstract methods.

PartialFunction currently is treated specially,
https://github.com/lampepfl/dotty/blob/master/src/dotty/tools/dotc/core/Types.scala#L2723-L2730
forcing it to be treated as a SAM.

The comment says that

// In the future it would be better to merge
// Function and PartialFunction, have Function1 contain a isDefinedAt method
//     def isDefinedAt(x: T) = true
// and overwrite that method whenever the function body is a sequence of
// case clauses.

The comment means that Function1 instances which are PartialFunctions could not be SAMs as they need to override a method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions