@@ -25,28 +25,29 @@ class SimpleState:
2525 pass
2626
2727
28- async def main ():
29- g = GraphBuilder(state_type = SimpleState, output_type = list[int ])
28+ g = GraphBuilder(state_type = SimpleState, output_type = list[int ])
3029
31- @g.step
32- async def generate_numbers (ctx : StepContext[SimpleState, None , None ]) -> list[int ]:
33- return [1 , 2 , 3 , 4 , 5 ]
30+ @g.step
31+ async def generate_numbers (ctx : StepContext[SimpleState, None , None ]) -> list[int ]:
32+ return [1 , 2 , 3 , 4 , 5 ]
3433
35- @g.step
36- async def square (ctx : StepContext[SimpleState, None , int ]) -> int :
37- return ctx.inputs * ctx.inputs
34+ @g.step
35+ async def square (ctx : StepContext[SimpleState, None , int ]) -> int :
36+ return ctx.inputs * ctx.inputs
3837
39- # Create a join to collect all squared values
40- collect = g.join(ListReducer[int ])
38+ # Create a join to collect all squared values
39+ collect = g.join(ListReducer[int ])
4140
42- g.add(
43- g.edge_from(g.start_node).to(generate_numbers),
44- g.edge_from(generate_numbers).map().to(square),
45- g.edge_from(square).to(collect),
46- g.edge_from(collect).to(g.end_node),
47- )
41+ g.add(
42+ g.edge_from(g.start_node).to(generate_numbers),
43+ g.edge_from(generate_numbers).map().to(square),
44+ g.edge_from(square).to(collect),
45+ g.edge_from(collect).to(g.end_node),
46+ )
4847
49- graph = g.build()
48+ graph = g.build()
49+
50+ async def main ():
5051 result = await graph.run(state = SimpleState())
5152 print (sorted (result))
5253 # > [1, 4, 9, 16, 25]
@@ -139,7 +140,7 @@ async def main():
139140 graph = g.build()
140141 result = await graph.run(state = SimpleState())
141142 print (result)
142- # > {'apple ': 5 , 'banana': 6, 'cherry ': 6 }
143+ # > {'cherry ': 6 , 'banana': 6, 'apple ': 5 }
143144```
144145
145146_ (This example is complete, it can be run "as is" — you'll need to add ` import asyncio; asyncio.run(main()) ` to run ` main ` )_
@@ -410,7 +411,7 @@ _(This example is complete, it can be run "as is" — you'll need to add `import
410411Like steps, joins can have custom IDs:
411412
412413``` python {title="join_custom_id.py" requires="basic_join.py"}
413- from basic_join import g, ListReducer
414+ from basic_join import ListReducer, g
414415
415416my_join = g.join(ListReducer[int ], node_id = ' my_custom_join_id' )
416417```
0 commit comments