diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/zclconf/go-cty/cty/map_type.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/map_type.go')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/map_type.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/map_type.go b/vendor/github.com/zclconf/go-cty/cty/map_type.go new file mode 100644 index 0000000..ae9abae --- /dev/null +++ b/vendor/github.com/zclconf/go-cty/cty/map_type.go | |||
@@ -0,0 +1,68 @@ | |||
1 | package cty | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | ) | ||
6 | |||
7 | // TypeList instances represent specific list types. Each distinct ElementType | ||
8 | // creates a distinct, non-equal list type. | ||
9 | type typeMap struct { | ||
10 | typeImplSigil | ||
11 | ElementTypeT Type | ||
12 | } | ||
13 | |||
14 | // Map creates a map type with the given element Type. | ||
15 | // | ||
16 | // Map types are CollectionType implementations. | ||
17 | func Map(elem Type) Type { | ||
18 | return Type{ | ||
19 | typeMap{ | ||
20 | ElementTypeT: elem, | ||
21 | }, | ||
22 | } | ||
23 | } | ||
24 | |||
25 | // Equals returns true if the other Type is a map whose element type is | ||
26 | // equal to that of the receiver. | ||
27 | func (t typeMap) Equals(other Type) bool { | ||
28 | ot, isMap := other.typeImpl.(typeMap) | ||
29 | if !isMap { | ||
30 | return false | ||
31 | } | ||
32 | |||
33 | return t.ElementTypeT.Equals(ot.ElementTypeT) | ||
34 | } | ||
35 | |||
36 | func (t typeMap) FriendlyName() string { | ||
37 | return "map of " + t.ElementTypeT.FriendlyName() | ||
38 | } | ||
39 | |||
40 | func (t typeMap) ElementType() Type { | ||
41 | return t.ElementTypeT | ||
42 | } | ||
43 | |||
44 | func (t typeMap) GoString() string { | ||
45 | return fmt.Sprintf("cty.Map(%#v)", t.ElementTypeT) | ||
46 | } | ||
47 | |||
48 | // IsMapType returns true if the given type is a list type, regardless of its | ||
49 | // element type. | ||
50 | func (t Type) IsMapType() bool { | ||
51 | _, ok := t.typeImpl.(typeMap) | ||
52 | return ok | ||
53 | } | ||
54 | |||
55 | // MapElementType is a convenience method that checks if the given type is | ||
56 | // a map type, returning a pointer to its element type if so and nil | ||
57 | // otherwise. This is intended to allow convenient conditional branches, | ||
58 | // like so: | ||
59 | // | ||
60 | // if et := t.MapElementType(); et != nil { | ||
61 | // // Do something with *et | ||
62 | // } | ||
63 | func (t Type) MapElementType() *Type { | ||
64 | if lt, ok := t.typeImpl.(typeMap); ok { | ||
65 | return <.ElementTypeT | ||
66 | } | ||
67 | return nil | ||
68 | } | ||