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/DynamicVariable

DynamicVariable

scala.util.DynamicVariable
classDynamicVariable[T](init:T)

DynamicVariables provide a binding mechanism where the current value is found through dynamic scope, but where access to the variable itself is resolved through static scope.

The current value can be retrieved with the value method. New values should be pushed using thewithValue method. Values pushed viawithValue only stay valid while thewithValue's second argument, a parameterless closure, executes. When the second argument finishes, the variable reverts to the previous value.

someDynamicVariable.withValue(newValue) {  // ... code called in here that calls value ...  // ... will be given back the newValue ...}

Each thread gets its own stack of bindings. When a new thread is created, theDynamicVariable gets a copy of the stack of bindings from the parent thread, and from then on the bindings for the new thread are independent of those for the original thread.

Attributes

Source
DynamicVariable.scala
Graph
Supertypes
classObject
traitMatchable
classAny

Members list

Value members

Concrete methods

overridedeftoString: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
Source
DynamicVariable.scala
defvalue:T

Retrieve the current value

Retrieve the current value

Attributes

Source
DynamicVariable.scala
defvalue_=(newval:T):Unit

Change the currently bound value, discarding the old value.

Change the currently bound value, discarding the old value. Usually withValue() gives better semantics.

Attributes

Source
DynamicVariable.scala
defwithValue[S](newval:T)(thunk:=>S):S

Set the value of the variable while executing the specified thunk.

Set the value of the variable while executing the specified thunk.

Value parameters

newval

The value to which to set the variable

thunk

The code to evaluate under the new setting

Attributes

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

[8]ページ先頭

©2009-2025 Movatter.jp