SingletonFunctionBinding creates a singleton function definition to be used with all function overloads. Note, this approach works well if operand is expected to have a specific trait which it implements, e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.
(fn functions.FunctionOp, traits ...int)
| 539 | // Note, this approach works well if operand is expected to have a specific trait which it implements, |
| 540 | // e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings. |
| 541 | func SingletonFunctionBinding(fn functions.FunctionOp, traits ...int) FunctionOpt { |
| 542 | trait := 0 |
| 543 | for _, t := range traits { |
| 544 | trait = trait | t |
| 545 | } |
| 546 | return func(f *FunctionDecl) (*FunctionDecl, error) { |
| 547 | if f.singleton != nil { |
| 548 | return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name()) |
| 549 | } |
| 550 | f.singleton = &functions.Overload{ |
| 551 | Operator: f.Name(), |
| 552 | Function: fn, |
| 553 | OperandTrait: trait, |
| 554 | } |
| 555 | return f, nil |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | // SingletonAsyncBinding creates a singleton async function definition to be used with all function overloads. |
| 560 | // The provided function is called in its own goroutine with the provided context. The function should |