]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/zclconf/go-cty/cty/set_type.go
952a2d2baae864b04c0673332f773a890e593b69
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / zclconf / go-cty / cty / set_type.go
1 package cty
2
3 import (
4 "fmt"
5 )
6
7 type 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.
15 func 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.
25 func (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
34 func (t typeSet) FriendlyName() string {
35 return "set of " + t.ElementTypeT.FriendlyName()
36 }
37
38 func (t typeSet) ElementType() Type {
39 return t.ElementTypeT
40 }
41
42 func (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.
48 func (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 // }
61 func (t Type) SetElementType() *Type {
62 if lt, ok := t.typeImpl.(typeSet); ok {
63 return &lt.ElementTypeT
64 }
65 return nil
66 }