LazyThrowing

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

A lazily computed value whose computation might throw.

The actual value is not computed unless accessed and is computed no more than once no matter how many times this value is copied or accessed. If the value computation throws, each access to this value (or copy of it) throws the same error as the original access.

  • The hidden state of an instance.

    See more

    Declaration

    Swift

    private 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 () throws -> T)
  • The (lazily) computed value.

    Throws

    Throws the error thrown by the computation if any.

    Declaration

    Swift

    public subscript() -> T { get throws }