Documentation

Lean.Server.AsyncList

inductive IO.AsyncList (ε : Type u) (α : Type v) :
Type (max u v)

An async IO list is like a lazy list but instead of being unevaluated Thunks, delayed suffixes are Tasks being evaluated asynchronously. A delayed suffix can signal the end of computation (successful or due to a failure) with a terminating value of type ε.

Instances For
instance IO.AsyncList.instInhabited {ε : Type u_1} {α : Type u_2} :
Equations
partial def IO.AsyncList.append {ε : Type u_1} {α : Type u_2} :
AsyncList ε αAsyncList ε αAsyncList ε α
instance IO.AsyncList.instAppend {ε : Type u_1} {α : Type u_2} :
Equations
instance IO.AsyncList.instCoeList {α : Type u_1} {ε : Type u_2} :
Coe (List α) (AsyncList ε α)
Equations
def IO.AsyncList.unfoldAsync {σ ε α : Type} (f : StateT σ (EIO ε) (Option α)) (init : σ) :

A stateful step computation f is applied iteratively, forming an async stream. The stream ends once f returns none for the first time.

For cooperatively cancelling an ongoing computation, we recommend referencing a cancellation token in f and checking it when appropriate.

Equations
partial def IO.AsyncList.unfoldAsync.step {σ ε α : Type} (f : StateT σ (EIO ε) (Option α)) (s : σ) :
EIO ε (AsyncList ε α)
partial def IO.AsyncList.getAll {ε : Type u_1} {α : Type u_2} :
AsyncList ε αList α × Option ε

The computed, synchronous list. If an async tail was present, returns also its terminating value.

partial def IO.AsyncList.waitUntil {α : Type u_1} {ε : Type u_2} (p : αBool) :
AsyncList ε αTask (List α × Option ε)

Spawns a Task returning the prefix of elements up to (including) the first element for which p is true. When p is not true of any element, it returns the entire list.

def IO.AsyncList.waitAll {ε : Type u_1} {α : Type u_2} :
AsyncList ε αTask (List α × Option ε)

Spawns a Task waiting on all elements.

Equations
partial def IO.AsyncList.waitFind? {α : Type u_1} {ε : Type u_2} (p : αBool) :
AsyncList ε αTask (Except ε (Option α))

Spawns a Task acting like List.find? but which will wait for tail evaluation when necessary to traverse the list. If the tail terminates before a matching element is found, the task throws the terminating value.

partial def IO.AsyncList.getFinishedPrefix {ε α : Type} :
AsyncList ε αBaseIO (List α × Option ε)

Retrieve the already-computed prefix of the list. If computation has finished with an error, return it as well.

def IO.AsyncList.waitHead? {ε : Type u_1} {α : Type u_2} (as : AsyncList ε α) :
Task (Except ε (Option α))
Equations
partial def IO.AsyncList.cancel {ε : Type u_1} {α : Type u_2} :

Cancels all tasks in the list.