Renderingen-US

yield

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Yields one value from a generator.

Aliases: yield

Syntax: yield <expression>

Category#

async

Examples#

radix/corpus/cede/cede.fab (canonical · keyword)#

Yields one value from a generator.

# =============================================================================
# yield — Yields one value from a generator.
# =============================================================================
#
# What this teaches:
#   • Yield — `yield <expression>` emits one item from a `generator` or `async_generator`
#     callable
#   • Async values use `await_const`, `await_var`, `return_await`, or `await`; `yield`
#     is not an await form
#
# Common mistakes:
#   • using `yield` outside a generator body
#
# See also: cursor, generator, async_generator
# =============================================================================

# yield — yield from a stream function
#
# fn stream() generator → T { yield value }
#
# GRAMMAR:
#   yieldStmt :← 'yield' expr
#
# EXPECTED OUTPUT:
#   [1, 2]
#
# BACKEND:
#   Cursor stream materialization smoke.

fn stream() generator → int {
    yield 1
    yield 2
}

main {
    print stream()
}

Expected output:

[1, 2]