SingletonBinaryBinding 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.BinaryOp, traits ...int)
| 517 | // Note, this approach works well if operand is expected to have a specific trait which it implements, |
| 518 | // e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings. |
| 519 | func SingletonBinaryBinding(fn functions.BinaryOp, traits ...int) FunctionOpt { |
| 520 | trait := 0 |
| 521 | for _, t := range traits { |
| 522 | trait = trait | t |
| 523 | } |
| 524 | return func(f *FunctionDecl) (*FunctionDecl, error) { |
| 525 | if f.singleton != nil { |
| 526 | return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name()) |
| 527 | } |
| 528 | f.singleton = &functions.Overload{ |
| 529 | Operator: f.Name(), |
| 530 | Binary: fn, |
| 531 | OperandTrait: trait, |
| 532 | } |
| 533 | return f, nil |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | // SingletonFunctionBinding creates a singleton function definition to be used with all function overloads. |
| 538 | // |