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