scalafoldpass-by-name

How should i understand this definition "final def fold[B](ifEmpty: => B)(f: (A) => B): B"


i knew this question might be dumb.

I just found myself have difficulty understanding the fold definition from Scala Optionlink.

Can anyone help me to understand the definition part? final def fold[B](ifEmpty: => B)(f: (A) => B): B

What does (ifEmpty: => B) mean, does the ifEmpty here represents a function? What does the right part => B represent? Does it represent a function without any parameter? Should that be () => B?


Solution

  • There is quite a lot of going on in definition of

    final def fold[B](ifEmpty: => B)(f: (A) => B): B
    

    We have