@@ -77,8 +77,9 @@ Flyt provides two styles of helper functions for creating nodes:
7777Use ` WithPrepFunc ` , ` WithExecFunc ` , and ` WithPostFunc ` for type-safe operations with the Result type:
7878
7979``` go
80- node := flyt.NewNode (
81- flyt.WithPrepFuncAny (func (ctx context .Context , shared *flyt .SharedStore ) (flyt .Result , error ) {
80+ // Using fluent API for cleaner chaining
81+ node := flyt.NewNode ().
82+ WithPrepFunc (func (ctx context .Context , shared *flyt .SharedStore ) (flyt .Result , error ) {
8283 // Use type-safe getters
8384 message := shared.GetString (" message" )
8485 retryCount := shared.GetIntOr (" retry_count" , 0 )
@@ -87,17 +88,17 @@ node := flyt.NewNode(
8788 " message" : message,
8889 " retry" : retryCount,
8990 }), nil
90- }),
91- flyt. WithExecFuncAny (func (ctx context .Context , prepResult flyt .Result ) (flyt .Result , error ) {
91+ }).
92+ WithExecFunc (func (ctx context .Context , prepResult flyt .Result ) (flyt .Result , error ) {
9293 // Type-safe access to data
9394 data := prepResult.AsMapOr (nil )
9495 message := data[" message" ].(string )
9596
9697 // Process and return Result
9798 processed := processMessage (message)
9899 return flyt.NewResult (processed), nil
99- }),
100- flyt. WithPostFuncAny (func (ctx context .Context , shared *flyt .SharedStore , prepResult , execResult flyt .Result ) (flyt .Action , error ) {
100+ }).
101+ WithPostFunc (func (ctx context .Context , shared *flyt .SharedStore , prepResult , execResult flyt .Result ) (flyt .Action , error ) {
101102 // Type-safe result handling
102103 result := execResult.Value ()
103104 shared.Set (" result" , result)
@@ -106,17 +107,17 @@ node := flyt.NewNode(
106107 return " max_retries" , nil
107108 }
108109 return flyt.DefaultAction , nil
109- }),
110- )
110+ })
111111```
112112
113113#### Any-based Functions (Simple)
114114
115115Use ` WithPrepFuncAny ` , ` WithExecFuncAny ` , and ` WithPostFuncAny ` for simpler cases or backward compatibility:
116116
117117``` go
118- node := flyt.NewNode (
119- flyt.WithPrepFuncAny (func (ctx context .Context , shared *flyt .SharedStore ) (any , error ) {
118+ // Using fluent API with any-based functions
119+ node := flyt.NewNode ().
120+ WithPrepFuncAny (func (ctx context .Context , shared *flyt .SharedStore ) (any , error ) {
120121 // Direct any types
121122 message := shared.GetString (" message" )
122123 retryCount := shared.GetIntOr (" retry_count" , 0 )
@@ -125,22 +126,21 @@ node := flyt.NewNode(
125126 " message" : message,
126127 " retry" : retryCount,
127128 }, nil
128- }),
129- flyt. WithExecFuncAny (func (ctx context .Context , prepResult any ) (any , error ) {
129+ }).
130+ WithExecFuncAny (func (ctx context .Context , prepResult any ) (any , error ) {
130131 data := prepResult.(map [string ]any)
131132 // Process the data
132133 return processMessage (data[" message" ].(string )), nil
133- }),
134- flyt. WithPostFuncAny (func (ctx context .Context , shared *flyt .SharedStore , prepResult , execResult any ) (flyt .Action , error ) {
134+ }).
135+ WithPostFuncAny (func (ctx context .Context , shared *flyt .SharedStore , prepResult , execResult any ) (flyt .Action , error ) {
135136 // Store result and determine action
136137 shared.Set (" result" , execResult)
137138
138139 if shared.GetInt (" retry_count" ) > 3 {
139140 return " max_retries" , nil
140141 }
141142 return flyt.DefaultAction , nil
142- }),
143- )
143+ })
144144```
145145
146146### Choosing Between Result and Any
@@ -192,24 +192,31 @@ func (n *DatabaseNode) Exec(ctx context.Context, prepResult any) (any, error) {
192192Configure node behavior with options:
193193
194194``` go
195- // With Result type
196- node := flyt.NewNode (
197- flyt. WithExecFuncAny (func (ctx context .Context , input flyt .Result ) (flyt .Result , error ) {
195+ // With Result type using fluent API
196+ node := flyt.NewNode ().
197+ WithExecFunc (func (ctx context .Context , input flyt .Result ) (flyt .Result , error ) {
198198 // Type-safe operations
199199 return flyt.NewResult (processData (input.Value ())), nil
200- }),
201- flyt.WithMaxRetries (3 ), // Retry up to 3 times
202- flyt.WithWait (time.Second * 2 ), // Wait 2 seconds between retries
203- )
200+ }).
201+ WithMaxRetries (3 ). // Retry up to 3 times
202+ WithWait (time.Second * 2 ) // Wait 2 seconds between retries
204203
205- // With any type
204+ // With any type using fluent API
205+ node := flyt.NewNode ().
206+ WithExecFuncAny (func (ctx context .Context , input any ) (any , error ) {
207+ // Direct any handling
208+ return processData (input), nil
209+ }).
210+ WithMaxRetries (3 ). // Retry up to 3 times
211+ WithWait (time.Second * 2 ) // Wait 2 seconds between retries
212+
213+ // Traditional style still supported
206214node := flyt.NewNode (
207215 flyt.WithExecFuncAny (func (ctx context .Context , input any ) (any , error ) {
208- // Direct any handling
209216 return processData (input), nil
210217 }),
211- flyt.WithMaxRetries (3 ), // Retry up to 3 times
212- flyt.WithWait (time.Second * 2 ), // Wait 2 seconds between retries
218+ flyt.WithMaxRetries (3 ),
219+ flyt.WithWait (time.Second * 2 ),
213220)
214221```
215222
0 commit comments