Renderingen-US

generator

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

Callable posture for synchronous stream (generator) functions.

Aliases: generator

Syntax: fn name(…) generator → T

Category#

async

Examples#

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

Callable posture for synchronous stream (generator) functions.

# =============================================================================
# generator — Synchronous stream callable posture
# =============================================================================
#
# What this teaches:
#   • Preferred stream posture: `generator → T` yields `T` items.
#   • Yield with statement-initial `yield value` inside the body.
#
# Common mistakes:
#   • Using `@ cursor` only when teaching preferred morphology — prefer `generator`.
#
# See also: cursor, yield, async_generator
# =============================================================================

# GRAMMAR:
#   callablePosture :← 'generator'
#   yieldStmt :← 'yield' expr
#
# EXPECTED OUTPUT:
#   [1, 2]

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

main {
    print stream()
}

Expected output:

[1, 2]