Function0

scala.Function0
trait Function0[+R] extends AnyRef

A function of 0 parameters.

In the following example, the definition of greeting is shorthand, conceptually, for the anonymous class definition anonfun0, although the implementation details of how the function value is constructed may differ:

object Main extends App {
  val name = "world"
  val greeting = () => s"hello, $name"

  val anonfun0 = new Function0[String] {
    def apply(): String = s"hello, $name"
  }
  assert(greeting() == anonfun0())
}

Attributes

Source
Function0.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Self type
() => R

Members list

Value members

Abstract methods

def apply(): R

Apply the body of this function to the arguments.

Apply the body of this function to the arguments.

Attributes

Returns

the result of function application.

Source
Function0.scala

Concrete methods

override def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
Source
Function0.scala