aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/function/unpredictable.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/function/unpredictable.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/function/unpredictable.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/function/unpredictable.go b/vendor/github.com/zclconf/go-cty/cty/function/unpredictable.go
new file mode 100644
index 0000000..3495550
--- /dev/null
+++ b/vendor/github.com/zclconf/go-cty/cty/function/unpredictable.go
@@ -0,0 +1,31 @@
1package function
2
3import (
4 "github.com/zclconf/go-cty/cty"
5)
6
7// Unpredictable wraps a given function such that it retains the same arguments
8// and type checking behavior but will return an unknown value when called.
9//
10// It is recommended that most functions be "pure", which is to say that they
11// will always produce the same value given particular input. However,
12// sometimes it is necessary to offer functions whose behavior depends on
13// some external state, such as reading a file or determining the current time.
14// In such cases, an unpredictable wrapper might be used to stand in for
15// the function during some sort of prior "checking" phase in order to delay
16// the actual effect until later.
17//
18// While Unpredictable can support a function that isn't pure in its
19// implementation, it still expects a function to be pure in its type checking
20// behavior, except for the special case of returning cty.DynamicPseudoType
21// if it is not yet able to predict its return value based on current argument
22// information.
23func Unpredictable(f Function) Function {
24 newSpec := *f.spec // shallow copy
25 newSpec.Impl = unpredictableImpl
26 return New(&newSpec)
27}
28
29func unpredictableImpl(args []cty.Value, retType cty.Type) (cty.Value, error) {
30 return cty.UnknownVal(retType), nil
31}