Lazy

public struct Lazy<T> where T : Sendable
extension Lazy: Sendable where T: Sendable

A lazily computed value.

The value is not computed unless accessed and is computed no more than once no matter how many times it is copied or accessed.

  • The hidden state of an instance.

    See more

    Declaration

    Swift

    enum State : Sendable
  • The hidden state of an instance.

    Declaration

    Swift

    private let state: SharedMutable<State>
  • Creates an instance whose value is computeValue().

    Requires

    computeValue does not mutate any existing state.

    Warning

    Swift silently creates mutable captures in closures! If computeValue mutates anything other than its local variables, you can create data races and undefined behavior.

    Declaration

    Swift

    public init(_ computeValue: @Sendable @escaping () -> T)
  • The (lazily) computed value.

    Declaration

    Swift

    public subscript() -> T { get }