Comments (2)
Running into this as well. Since transform encodes elements by pushing the entire element into IndexStep, this code may need to be made to handle it:
func (s IndexStep) Apply(val Value) (Value, error) {
if val == NilVal || val.IsNull() {
return NilVal, errors.New("cannot index a null value")
}
switch s.Key.Type() {
case Number:
if !(val.Type().IsListType() || val.Type().IsTupleType()) {
return NilVal, errors.New("not a list type")
}
case String:
if !val.Type().IsMapType() {
return NilVal, errors.New("not a map type")
}
default:
return NilVal, errors.New("key value not number or string")
}
has := val.HasIndex(s.Key)
if !has.IsKnown() {
return UnknownVal(val.Type().ElementType()), nil
}
if !has.True() {
return NilVal, errors.New("value does not have given index key")
}
return val.Index(s.Key), nil
}
What's available:
type Set struct {
vals map[int][]interface{}
rules Rules
}
// Rules represents the operations that define membership for a Set.
//
// Each Set has a Rules instance, whose methods must satisfy the interface
// contracts given below for any value that will be added to the set.
type Rules interface {
// Hash returns an int that somewhat-uniquely identifies the given value.
//
// A good hash function will minimize collisions for values that will be
// added to the set, though collisions *are* permitted. Collisions will
// simply reduce the efficiency of operations on the set.
Hash(interface{}) int
// Equivalent returns true if and only if the two values are considered
// equivalent for the sake of set membership. Two values that are
// equivalent cannot exist in the set at the same time, and if two
// equivalent values are added it is undefined which one will be
// returned when enumerating all of the set members.
//
// Two values that are equivalent *must* result in the same hash value,
// though it is *not* required that two values with the same hash value
// be equivalent.
Equivalent(interface{}, interface{}) bool
}
So IndexStep{v}.Apply(Set{}) should probably try to use the Rules on the set to find an equivalent value to v
.
from go-cty.
Possible fix in #183
from go-cty.
Related Issues (20)
- Extend FormatDateFunc to support seconds since Unix Epoch HOT 4
- Consider using "hash/maphash" for set element hashing HOT 1
- 1.11.0 causes errors with //go:generate packer-sdc mapstructure-to-hcl2 HOT 1
- hashicorp/packer-plugin-sdk incompatible with zclconf/go-cty v1.11.0 HOT 4
- TestFormatDate fails with upcoming Go 1.20 release HOT 5
- Add support for decoding into structs with a custom tag HOT 1
- Nested go struct to cty value fails HOT 1
- Proposal: JSON serialization of `cty.Path` HOT 3
- cty/json: configure (non-)HTML-escaping serialization HOT 3
- stdlib: SetProductFunc doesn't seem to handle refinements quite right HOT 2
- How to convert cty.Value of unknown type into `interface{}` HOT 2
- cty.StringVal always doubles $ in `${}` output HOT 2
- Parse string into cty type HOT 1
- cty.StringVal always doubles $ in ${} output Pt2 HOT 1
- adding jsonencode() block into a generated terraform file using golang cty HOT 2
- Encoding values with custom function (terraform provider) HOT 1
- Marshal() generate invalid JSON HOT 2
- panic with `AsString()` on result of json encoding of to_number conversion of null value HOT 4
- Add a deepmerge function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-cty.