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