kw for
Reserved keyword
The list of words: §1.4
Syntax
Impl = "impl" [ Type "for" ] Type "{" { ImplMember } "}" ;Provide = "provide" Type "=" Expr [ "for" "role" IdentList ] ;For = [ Label ":" ] [ "inline" ] "for" [ "await" ] Pattern "in" Expr [ "where" Expr ] Block ;Grammar: App. A
Defined in
- 5.6 Loops — for accepts Iterable<T> (including iter<T>, collections, ranges); for await accepts Streamable<T>.
- 1.4 Keywords — Reserved (cannot be used as names)
- 4.6 Interfaces — Interfaces are structural
- 3.8 Asynchronous and stream types — Asynchronous and stream types
- 10.3 Streams — The type is stream<T, E = never>.
- 10.5 Topics — cluster-wide fan-out — A topic is a distributed broadcast with storage in the built-in storage.
- 14.2 Dynamic configuration — dynamic Name { …
- 8.2 Suspension points — A task can yield its thread only at suspension points
Examples
for u in users { … }
for (i, u) in users.enumerate() { … }
for i in 0..n where i % 2 == 0 { … } // filter
for await msg in input { … } // stream<T>
while cond { … }
while let x? = queue.pop() { … }
loop { if done { break result } } // loop is an expression
'outer: for a in xs { for b in ys { if a == b { break 'outer } } }@retain(ORDER_EVENTS_RETENTION)
topic OrderEvents: OrderEvent sharded by .userId
emit OrderEvents(e) // publication
for await e in OrderEvents.subscribe(key: uid, from: .Latest) { … }
for await e in OrderEvents.subscribe(group: "indexer") { index(e) }— 10.5 Topics — cluster-wide fan-out
Related diagnostics
break-value, outside-loop, explicit-interface, interface-not-satisfied, yield-outside-stream, topic-without-journal