Skip to main content

Computed<T> class

Namespace: Arlecchino.Atoms · Assembly: Arlecchino.Core

A value derived from other atoms. It re-evaluates lazily and tracks whatever it read while doing so, including other computed values and branches taken only sometimes — reading other.Value inside the lambda is the subscription.

public sealed class Computed<T> : IReadableAtom<T>

Implements IReadableAtom<T>

Constructors

MemberSummary
Computed(Func<T>)Creates a derived value.

Properties

MemberSummary
ValueThe derived value, recomputed on the first read after any dependency changed.

Methods

MemberSummary
Subscribe(Action)Calls back whenever the derived value goes stale.

Constructors in detail

Computed(Func<T>)

public Computed(Func<T> compute);

Creates a derived value.

Parameters

NameTypeDescription
computeFunc<TResult><T>How to work it out. Reads of other atoms inside become the dependencies, so it may read different ones on different runs.

Properties in detail

Value

public T Value { get; }

The derived value, recomputed on the first read after any dependency changed.

Type T

Methods in detail

Subscribe(Action)

public IDisposable Subscribe(Action listener);

Calls back whenever the derived value goes stale.

Parameters

NameTypeDescription
listenerActionWhat to run on change.

Returns IDisposable — Dispose it to stop listening.