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)
| 521 | // Note, this approach works well if operand is expected to have a specific trait which it implements, |
| 522 | // e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings. |
| 523 | func SingletonFunctionBinding(fn functions.FunctionOp, traits ...int) FunctionOpt { |
| 524 | trait := 0 |
| 525 | for _, t := range traits { |
| 526 | trait = trait | t |
| 527 | } |
| 528 | return func(f *FunctionDecl) (*FunctionDecl, error) { |
| 529 | if f.singleton != nil { |
| 530 | return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name()) |
| 531 | } |
| 532 | f.singleton = &functions.Overload{ |
| 533 | Operator: f.Name(), |
| 534 | Function: fn, |
| 535 | OperandTrait: trait, |
| 536 | } |
| 537 | return f, nil |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | // Overload defines a new global overload with an overload id, argument types, and result type. Through the |
| 542 | // use of OverloadOpt options, the overload may also be configured with a binding, an operand trait, and to |