Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.util/boundary

boundary

scala.util.boundary
objectboundary

A boundary that can be exited bybreak calls.boundary andbreak represent a unified and superior alternative for thescala.util.control.NonLocalReturns andscala.util.control.Breaks APIs. The main differences are:

  • Unified names:boundary to establish a scope,break to leave it.break can optionally return a value.
  • Integration with exceptions.breaks are logically non-fatal exceptions. TheBreak exception class extendsRuntimeException and is optimized so that stack trace generation is suppressed.
  • Better performance: breaks to enclosing scopes in the same method can be rewritten to jumps.

Example usage:

import scala.util.boundary, boundary.breakdef firstIndex[T](xs: List[T], elem: T): Int = boundary:   for (x, i) <- xs.zipWithIndex do     if x == elem then break(i)   -1

Attributes

Source
boundary.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Self type

Members list

Type members

Classlikes

finalclassBreak[T] extendsRuntimeException

User code should callbreak.apply instead of throwing this exception directly.

User code should callbreak.apply instead of throwing this exception directly.

Attributes

Source
boundary.scala
Supertypes
classException
classThrowable
classObject
traitMatchable
classAny
Show all
finalclassLabel[-T]

Labels are targets indicating which boundary will be exited by abreak.

Labels are targets indicating which boundary will be exited by abreak.

Attributes

Source
boundary.scala
Supertypes
classObject
traitMatchable
classAny

Value members

Concrete methods

inlinedefapply[T](inlinebody:Label[T]?=>T):T

Runbody with freshly generated label as implicit argument. Catch any breaks associated with that label and return their results instead ofbody's result.

Runbody with freshly generated label as implicit argument. Catch any breaks associated with that label and return their results instead ofbody's result.

Attributes

Source
boundary.scala
defbreak[T](value:T)(usinglabel:Label[T]):Nothing

Abort current computation and instead returnvalue as the value of the enclosingboundary call that createdlabel.

Abort current computation and instead returnvalue as the value of the enclosingboundary call that createdlabel.

Attributes

Source
boundary.scala
defbreak()(usinglabel:Label[Unit]):Nothing

Abort current computation and instead continue after theboundary call that createdlabel.

Abort current computation and instead continue after theboundary call that createdlabel.

Attributes

Source
boundary.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp