diff --git a/lib/collections.go b/lib/collections.go index 0672836..4a1be54 100644 --- a/lib/collections.go +++ b/lib/collections.go @@ -358,8 +358,8 @@ func (collectionsLib) CompileOptions() []cel.EnvOption { cel.Function("flatten", cel.MemberOverload( "list_flatten", - []*cel.Type{listV}, - listV, + []*cel.Type{listDyn}, + listDyn, cel.UnaryBinding(flatten), ), ), diff --git a/testdata/flatten_types.txt b/testdata/flatten_types.txt new file mode 100644 index 0000000..e2de303 --- /dev/null +++ b/testdata/flatten_types.txt @@ -0,0 +1,87 @@ +mito -use collections -data state.json src.cel +! stderr . +cmp stdout want.txt + +-- state.json -- +{ + "aye": { + "value": 1 + }, + "bee": { + "value": "two" + }, + "one": [ + { + "value": 1 + }, + { + "value": "two" + } + ], + "two": [ + { + "value": 3 + }, + { + "value": "four" + } + ] +} + +-- src.cel -- +[ + "one", + "two", +].map(k, state[k].map(e, { + k: e, +})).flatten().map(d, d.with({ + "aye": state.aye, + "bee": state.bee, +})) +-- want.txt -- +[ + { + "aye": { + "value": 1 + }, + "bee": { + "value": "two" + }, + "one": { + "value": 1 + } + }, + { + "aye": { + "value": 1 + }, + "bee": { + "value": "two" + }, + "one": { + "value": "two" + } + }, + { + "aye": { + "value": 1 + }, + "bee": { + "value": "two" + }, + "two": { + "value": 3 + } + }, + { + "aye": { + "value": 1 + }, + "bee": { + "value": "two" + }, + "two": { + "value": "four" + } + } +]