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