aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/set_type.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/set_type.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/set_type.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/set_type.go b/vendor/github.com/zclconf/go-cty/cty/set_type.go
new file mode 100644
index 0000000..952a2d2
--- /dev/null
+++ b/vendor/github.com/zclconf/go-cty/cty/set_type.go
@@ -0,0 +1,66 @@
1package cty
2
3import (
4 "fmt"
5)
6
7type typeSet struct {
8 typeImplSigil
9 ElementTypeT Type
10}
11
12// Set creates a set type with the given element Type.
13//
14// Set types are CollectionType implementations.
15func Set(elem Type) Type {
16 return Type{
17 typeSet{
18 ElementTypeT: elem,
19 },
20 }
21}
22
23// Equals returns true if the other Type is a set whose element type is
24// equal to that of the receiver.
25func (t typeSet) Equals(other Type) bool {
26 ot, isSet := other.typeImpl.(typeSet)
27 if !isSet {
28 return false
29 }
30
31 return t.ElementTypeT.Equals(ot.ElementTypeT)
32}
33
34func (t typeSet) FriendlyName() string {
35 return "set of " + t.ElementTypeT.FriendlyName()
36}
37
38func (t typeSet) ElementType() Type {
39 return t.ElementTypeT
40}
41
42func (t typeSet) GoString() string {
43 return fmt.Sprintf("cty.Set(%#v)", t.ElementTypeT)
44}
45
46// IsSetType returns true if the given type is a list type, regardless of its
47// element type.
48func (t Type) IsSetType() bool {
49 _, ok := t.typeImpl.(typeSet)
50 return ok
51}
52
53// SetElementType is a convenience method that checks if the given type is
54// a set type, returning a pointer to its element type if so and nil
55// otherwise. This is intended to allow convenient conditional branches,
56// like so:
57//
58// if et := t.SetElementType(); et != nil {
59// // Do something with *et
60// }
61func (t Type) SetElementType() *Type {
62 if lt, ok := t.typeImpl.(typeSet); ok {
63 return &lt.ElementTypeT
64 }
65 return nil
66}