Skip to main content

Dynamic branches and lists

This reference documents every current public declaration in this part of Pine. Examples run inside App.Mount(), a component factory, or an explicit UI.Root(...) unless they only create state/configuration. Explicit UI.Mount(...) remains available for advanced ownership. Variable names such as count, items and label refer to the typed values described by each example. All APIs run on Unity’s main thread.

Branch​

Branch<T>

A constructed dynamic result and its optional exit retention delay in seconds. Presence becomes false immediately on removal while the result remains alive for ExitDelay; reentry before expiration cancels removal and reuses its scope. Zero delay removes immediately. Delays must be finite and non-negative.

Type parameterMeaning
TTyped value, native result or identity contract; see the summary for its role.
UI.Show(
condition: () => true,
build: present => new Branch<UnityEngine.Component>(
UI.Label(text: () => present.Value ? "Present" : "Leaving"),
0.2
)
);

Branch.Value​

T Value

The native or custom result retained by this branch's scope.

UnityEngine.Component result = branch.Value;

Branch.ExitDelay​

double ExitDelay

Finite non-negative seconds to retain an exiting branch after its presence becomes false. Zero removes immediately.

double seconds = branch.ExitDelay;

Branch.Branch​

public Branch(T value, double exitDelay = 0)

Constructs this value with the supplied typed arguments. A constructed dynamic result and its optional exit retention delay in seconds. Presence becomes false immediately on removal while the result remains alive for ExitDelay; reentry before expiration cancels removal and reuses its scope. Zero delay removes immediately. Delays must be finite and non-negative.

ParameterMeaning
valueThe typed value or reactive input to read/apply; sources remain observable for the owning lifetime.
exitDelayFinite non-negative seconds to retain a branch after presence becomes false.
UI.Show(
condition: () => true,
build: present => new Branch<UnityEngine.Component>(
UI.Label(text: () => present.Value ? "Present" : "Leaving"),
0.2
)
);

Branch.implicit​

public static implicit operator Branch<T>(T value)

Converts a constructed result into a branch with zero exit delay. Use the explicit constructor for retained exit animation.

ParameterMeaning
valueThe typed value or reactive input to read/apply; sources remain observable for the owning lifetime.

Returns: A typed Value adapter that reads this reactive value when evaluated; the conversion does not write to its source.

Branch<string> branch = "Ready";

UI.Show​

public static ReadOnly<IReadOnlyList<TResult>> Show<TResult>(Func<bool> condition, Func<TResult> build, Func<TResult> fallback = null)

Constructs an owned conditional branch while its condition is true, with an optional fallback. The predicate overload retains the last truthy value for its branch. Results and presence are read-only; exit delays retain native results while presence is false, and reentry reuses unexpired scopes.

Type parameterMeaning
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
conditionReactive visibility predicate; its reads establish the controlling dependencies.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
fallbackOptional construction callback used when the selected primary branch is absent.

Returns: An observable, immutable list of current and retained-exit branch results.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var result = UI.Show(
condition: () => visible.Value,
build: () => UI.Label(text: "Visible")
);
UI.Frame(UI.Children(read: () => result.Value));

UI.Switch​

public static ReadOnly<IReadOnlyList<TResult>> Switch<TKey, TResult>(Func<TKey> select, Func<TKey, TResult> build, IEqualityComparer<TKey> comparer = null)

Retains the selected keyed branch and optionally its exiting predecessor. Selection keys must be non-null; a comparer controls identity. Dictionary overloads support a fallback. Branch callbacks run only when creating that keyed scope, and returned presence/output are read-only.

Type parameterMeaning
TKeyTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
selectNative event selector or reactive branch selector, as specified by this overload.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
comparerOptional equality/identity comparer; null selects the documented default policy.

Returns: An observable, immutable list of selected and retained-exit branch results.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var result = UI.Switch(
select: () => page.Value,
build: key => UI.Label(text: key)
);
UI.Frame(UI.Children(read: () => result.Value));

UI.Indexes​

public static ReadOnly<IReadOnlyList<TResult>> Indexes<TValue, TResult>(Func<IReadOnlyList<TValue>> read, Func<int, ReadOnly<TValue>, TResult> build)

Retains rows by index or explicit dictionary key, updating each row's read-only reactive value. Use explicit stable item IDs to preserve rows across reordering or immutable item replacement. Keys must be unique and non-null. Presence supports delayed exits through Branch.

Type parameterMeaning
TValueTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
readThe getter whose source reads establish reactive dependencies; supply a stable native result where required.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.

Returns: An observable, immutable ordered list of row results; retained rows keep native identity.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var rows = UI.Indexes(
read: () => items.Value,
build: (index, item) => UI.Label(text: () => item.Value)
);
UI.Column(UI.Children(read: () => rows.Value));

UI.Values​

public static ReadOnly<IReadOnlyList<TResult>> Values<TValue, TResult>(Func<IReadOnlyList<TValue>> read, Func<TValue, ReadOnly<int>, TResult> build, IEqualityComparer<TValue> comparer = null)

Retains rows by value identity and exposes each current index as a read-only reactive value. Reordering preserves constructed rows; removed rows report index -1 and false presence during delayed exit. Duplicate or null identity values are rejected, and an optional comparer controls identity.

Type parameterMeaning
TValueTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
readThe getter whose source reads establish reactive dependencies; supply a stable native result where required.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
comparerOptional equality/identity comparer; null selects the documented default policy.

Returns: An observable, immutable ordered list of row results; indices are read-only operator-owned state.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var rows = UI.Values(
read: () => items.Value,
build: (item, index) => UI.Label(text: () => $"{index.Value}: {item}")
);
UI.Column(UI.Children(read: () => rows.Value));

UI.Switch​

public static ReadOnly<IReadOnlyList<TResult>> Switch<TKey, TResult>(Func<TKey> select, Func<TKey, ReadOnly<bool>, Branch<TResult>> build, IEqualityComparer<TKey> comparer = null)

Retains the selected keyed branch and optionally its exiting predecessor. Selection keys must be non-null; a comparer controls identity. Dictionary overloads support a fallback. Branch callbacks run only when creating that keyed scope, and returned presence/output are read-only.

Type parameterMeaning
TKeyTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
selectNative event selector or reactive branch selector, as specified by this overload.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
comparerOptional equality/identity comparer; null selects the documented default policy.

Returns: An observable, immutable list of selected and retained-exit branch results.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var result = UI.Switch(
select: () => page.Value,
build: key => UI.Label(text: key)
);
UI.Frame(UI.Children(read: () => result.Value));
public static ReadOnly<IReadOnlyList<TResult>> Switch<TKey, TResult>(Func<TKey> select, IReadOnlyDictionary<TKey, Func<ReadOnly<bool>, Branch<TResult>>> branches, Func<ReadOnly<bool>, Branch<TResult>> fallback = null)

Retains the selected keyed branch and optionally its exiting predecessor. Selection keys must be non-null; a comparer controls identity. Dictionary overloads support a fallback. Branch callbacks run only when creating that keyed scope, and returned presence/output are read-only.

Type parameterMeaning
TKeyTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
selectNative event selector or reactive branch selector, as specified by this overload.
branchesConstruction callbacks indexed by non-null identity keys.
fallbackOptional construction callback used when the selected primary branch is absent.

Returns: An observable, immutable list of selected and retained-exit branch results.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var result = UI.Switch(
select: () => page.Value,
build: key => UI.Label(text: key)
);
UI.Frame(UI.Children(read: () => result.Value));

UI.Show​

public static ReadOnly<IReadOnlyList<TResult>> Show<TResult>(Func<bool> condition, Func<ReadOnly<bool>, Branch<TResult>> build, Func<ReadOnly<bool>, Branch<TResult>> fallback = null)

Constructs an owned conditional branch while its condition is true, with an optional fallback. The predicate overload retains the last truthy value for its branch. Results and presence are read-only; exit delays retain native results while presence is false, and reentry reuses unexpired scopes.

Type parameterMeaning
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
conditionReactive visibility predicate; its reads establish the controlling dependencies.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
fallbackOptional construction callback used when the selected primary branch is absent.

Returns: An observable, immutable list of current and retained-exit branch results.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var result = UI.Show(
condition: () => visible.Value,
build: () => UI.Label(text: "Visible")
);
UI.Frame(UI.Children(read: () => result.Value));
public static ReadOnly<IReadOnlyList<TResult>> Show<T, TResult>(Func<T> read, Predicate<T> truthy, Func<ReadOnly<T>, ReadOnly<bool>, Branch<TResult>> build, Func<ReadOnly<bool>, Branch<TResult>> fallback = null)

Constructs an owned conditional branch while its condition is true, with an optional fallback. The predicate overload retains the last truthy value for its branch. Results and presence are read-only; exit delays retain native results while presence is false, and reentry reuses unexpired scopes.

Type parameterMeaning
TTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
readThe getter whose source reads establish reactive dependencies; supply a stable native result where required.
truthyPredicate determining whether the read value belongs to the visible branch.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
fallbackOptional construction callback used when the selected primary branch is absent.

Returns: An observable, immutable list of current and retained-exit branch results.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var result = UI.Show(
condition: () => visible.Value,
build: () => UI.Label(text: "Visible")
);
UI.Frame(UI.Children(read: () => result.Value));

UI.Indexes​

public static ReadOnly<IReadOnlyList<TResult>> Indexes<TKey, TValue, TResult>(Func<IEnumerable<KeyValuePair<TKey, TValue>>> read, Func<TKey, ReadOnly<TValue>, ReadOnly<bool>, Branch<TResult>> build, IEqualityComparer<TKey> comparer = null)

Retains rows by index or explicit dictionary key, updating each row's read-only reactive value. Use explicit stable item IDs to preserve rows across reordering or immutable item replacement. Keys must be unique and non-null. Presence supports delayed exits through Branch.

Type parameterMeaning
TKeyTyped value, native result or identity contract; see the summary for its role.
TValueTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
readThe getter whose source reads establish reactive dependencies; supply a stable native result where required.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
comparerOptional equality/identity comparer; null selects the documented default policy.

Returns: An observable, immutable ordered list of row results; retained rows keep native identity.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var rows = UI.Indexes(
read: () => items.Value,
build: (index, item) => UI.Label(text: () => item.Value)
);
UI.Column(UI.Children(read: () => rows.Value));
public static ReadOnly<IReadOnlyList<TResult>> Indexes<TValue, TResult>(Func<IReadOnlyList<TValue>> read, Func<int, ReadOnly<TValue>, ReadOnly<bool>, Branch<TResult>> build)

Retains rows by index or explicit dictionary key, updating each row's read-only reactive value. Use explicit stable item IDs to preserve rows across reordering or immutable item replacement. Keys must be unique and non-null. Presence supports delayed exits through Branch.

Type parameterMeaning
TValueTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
readThe getter whose source reads establish reactive dependencies; supply a stable native result where required.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.

Returns: An observable, immutable ordered list of row results; retained rows keep native identity.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var rows = UI.Indexes(
read: () => items.Value,
build: (index, item) => UI.Label(text: () => item.Value)
);
UI.Column(UI.Children(read: () => rows.Value));

UI.Values​

public static ReadOnly<IReadOnlyList<TResult>> Values<TValue, TResult>(Func<IReadOnlyList<TValue>> read, Func<TValue, ReadOnly<int>, ReadOnly<bool>, Branch<TResult>> build, IEqualityComparer<TValue> comparer = null)

Retains rows by value identity and exposes each current index as a read-only reactive value. Reordering preserves constructed rows; removed rows report index -1 and false presence during delayed exit. Duplicate or null identity values are rejected, and an optional comparer controls identity.

Type parameterMeaning
TValueTyped value, native result or identity contract; see the summary for its role.
TResultTyped value, native result or identity contract; see the summary for its role.
ParameterMeaning
readThe getter whose source reads establish reactive dependencies; supply a stable native result where required.
buildConstruction callback executed in its documented ownership scope; declare owned resources here.
comparerOptional equality/identity comparer; null selects the documented default policy.

Returns: An observable, immutable ordered list of row results; indices are read-only operator-owned state.

Ownership: Construct and apply declarations on Unity's main thread within UI.Mount, UI.Root or a live Scope.Run. Literal assignments occur once; reactive observers and handlers end with their owning scope.

var rows = UI.Values(
read: () => items.Value,
build: (item, index) => UI.Label(text: () => $"{index.Value}: {item}")
);
UI.Column(UI.Children(read: () => rows.Value));