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)
| 529 | // Note, this approach works well if operand is expected to have a specific trait which it implements, |
| 530 | // e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings. |
| 531 | func SingletonFunctionBinding(fn functions.FunctionOp, traits ...int) FunctionOpt { |
| 532 | trait := 0 |
| 533 | for _, t := range traits { |
| 534 | trait = trait | t |
| 535 | } |
| 536 | return func(f *FunctionDecl) (*FunctionDecl, error) { |
| 537 | if f.singleton != nil { |
| 538 | return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name()) |
| 539 | } |
| 540 | f.singleton = &functions.Overload{ |
| 541 | Operator: f.Name(), |
| 542 | Function: fn, |
| 543 | OperandTrait: trait, |
| 544 | } |
| 545 | return f, nil |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | // SingletonAsyncBinding creates a singleton async function definition to be used with all function overloads. |
| 550 | // The provided function is called in its own goroutine with the provided context. The function should |