0

Something as simple

class Thunk[+A](body: => A) {
  lazy val result: A = body;
}

Is it defined somewhere?

Or perhaps a slightly more sohpisticated

class Thunk[+A](body: => A) {
  private[this] var evaluatedInternal = false;

  lazy val result: A = {
    evaluatedInternal = true;
    body;
  }

  def evaluated: Boolean = evaluatedInternal;
}
Petr
  • 62,528
  • 13
  • 153
  • 317

1 Answers1

0

There are classes Name and Need in Scala that provide just that functionality. See also Scalaz Issue #427.

Petr
  • 62,528
  • 13
  • 153
  • 317