lang: types, funcs: Add simple function API
This patch adds a simple function API for writing simple, pure functions. This should reduce the amount of boilerplate required for most functions, and make growing a stdlib significantly easier. If you need to build more complex, event-generating functions, or statically polymorphic functions, then you'll still need to use the normal API for now. This also makes all of these pure functions available automatically within templates. It might make sense to group these functions into packages to make their logical organization easier, but this is a good enough start for now. Lastly, this added some missing pieces to our types library. You can now use `ValueOf` to convert from a `reflect.Value` to the corresponding `Value` in our type system, if an equivalent exists. Unfortunately, we're severely lacking in tests for these new types library additions, but look forward to growing some in the future!
This commit is contained in:
@@ -212,6 +212,8 @@ Your function must have a specific type. For example, a simple math function
|
||||
might have a signature of `func(x int, x int) int`. As you can see, all the
|
||||
types are known _before_ compile time.
|
||||
|
||||
A separate discussion on this matter can be found in the [function guide](function-guide.md).
|
||||
|
||||
What follows are each of the method signatures and a description of each.
|
||||
Failure to implement the API correctly can cause the function graph engine to
|
||||
block, or the program to panic.
|
||||
@@ -279,7 +281,7 @@ one value must be produced.
|
||||
#### Example
|
||||
```golang
|
||||
Please see the example functions in
|
||||
[lang/funcs/public/](https://github.com/purpleidea/mgmt/tree/master/lang/funcs/public/).
|
||||
[lang/funcs/core/](https://github.com/purpleidea/mgmt/tree/master/lang/funcs/core/).
|
||||
```
|
||||
|
||||
### Stream
|
||||
@@ -298,7 +300,7 @@ whether or not you close the `Output` channel.
|
||||
#### Example
|
||||
```golang
|
||||
Please see the example functions in
|
||||
[lang/funcs/public/](https://github.com/purpleidea/mgmt/tree/master/lang/funcs/public/).
|
||||
[lang/funcs/core/](https://github.com/purpleidea/mgmt/tree/master/lang/funcs/core/).
|
||||
```
|
||||
|
||||
### Close
|
||||
@@ -312,7 +314,7 @@ return.
|
||||
#### Example
|
||||
```golang
|
||||
Please see the example functions in
|
||||
[lang/funcs/public/](https://github.com/purpleidea/mgmt/tree/master/lang/funcs/public/).
|
||||
[lang/funcs/core/](https://github.com/purpleidea/mgmt/tree/master/lang/funcs/core/).
|
||||
```
|
||||
|
||||
### Polymorphic Function API
|
||||
|
||||
Reference in New Issue
Block a user