SingletonUnaryBinding creates a singleton function definition to be used for 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.UnaryOp, traits ...int)
| 477 | // Note, this approach works well if operand is expected to have a specific trait which it implements, |
| 478 | // e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings. |
| 479 | func SingletonUnaryBinding(fn functions.UnaryOp, traits ...int) FunctionOpt { |
| 480 | trait := 0 |
| 481 | for _, t := range traits { |
| 482 | trait = trait | t |
| 483 | } |
| 484 | return func(f *FunctionDecl) (*FunctionDecl, error) { |
| 485 | if f.singleton != nil { |
| 486 | return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name()) |
| 487 | } |
| 488 | f.singleton = &functions.Overload{ |
| 489 | Operator: f.Name(), |
| 490 | Unary: fn, |
| 491 | OperandTrait: trait, |
| 492 | } |
| 493 | return f, nil |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | // SingletonBinaryBinding creates a singleton function definition to be used with all function overloads. |
| 498 | // |