All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.dotc.util.optional.scala Maven / Gradle / Ivy

There is a newer version: 3.6.4-RC1-bin-20241220-0bfa1af-NIGHTLY
Show newest version
package dotty.tools.dotc.util

import scala.util.boundary

/** Return type that indicates that the method returns a T or aborts to the enclosing boundary with a `None` */
type optional[T] = boundary.Label[None.type] ?=> T

/** A prompt for `Option`, which establishes a boundary which `_.?` on `Option` can return */
object optional:
  inline def apply[T](inline body: optional[T]): Option[T] =
    boundary(Some(body))

  extension [T](r: Option[T])
    inline def ? (using label: boundary.Label[None.type]): T = r match
      case Some(x) => x
      case None => boundary.break(None)

  inline def break()(using label: boundary.Label[None.type]): Nothing =
    boundary.break(None)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy