Scope

Scope prototype extensions

Import

_ <- fat.type.Scope

Alias

Keyset: a list of keys (List/Text)

Constructor

Name Signature Brief
Scope (val: Any) Wrap val into a scope

Prototype members

Name Signature Brief
isEmpty <> Boolean Return true if size is zero
nonEmpty <> Boolean Return true if non-zero size
size <> Number Return number of entries
toText <> Text Return 'Scope' text literal
some <> Option Wrap value into Option
freeze <> Void Make the value immutable
seal <> Void Prevents scope growth
isSealed <> Boolean Check if scope is sealed
copy <> Scope Return deep copy of scope
keys <> Keyset Return list of scope keys
keysOf (val: Any): Keyset Get keys that match val
valuesOf (t: Type): List Get values matching type t
pick (keys: Keyset): Scope Filter scope by keys
omit (keys: Keyset): Scope Filter scope removing keys
vmap (m: Method): Scope Map values (m = v1 -> v2)
maybe (key: Text): Option Return Option wrapped value

copy

copy recursively copies a scope and its nested collections. Since v4.7.0, cyclic references reconnect to the copy being built, including cycles through nested lists:

_ <- fat.type.Scope

original = { ~ value = 1 }
original.me = original
copied = original.copy
copied.value = 2

copied.me.value    # yields 2
original.me.value  # yields 1

A repeated reference to a collection that has already finished copying remains shared with the original. Only references back into the current chain of copies reconnect to the new collections, so copy does not guarantee complete isolation for every shared object graph. Methods bound to a copied scope are rebound to that copy.

Example

_ <- fat.type.Scope
x = { num = 12, prop = 'other' }
x.size  # yields 2

See also

results matching ""

    No results matching ""