Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the spread
...
operator, other new functions, and indices…
… on lambdas (#13658) Adds the spread operator `...` as well as various new functions + indexes on lambdas: 1. Spread operator - usage is as follows: * In an object: ```bicep var objA = { bar: 'bar' } var objB = { foo: 'foo', ...objA } // equivalent to { foo: 'foo', bar: 'bar' } ``` * In an array: ```bicep var arrA = [ 2, 3 ] var arrB = [ 1, ...arrA, 4 ] // equivalent to [ 1, 2, 3, 4 ] ``` 1. New functions + usage: * `objectKeys`: Returns the keys of an object parameter: ```bicep var example = objectKeys({ a: 1, b: 2 }) // returns [ 'a', 'b' ] ``` * `mapValues`: Create an object from an input object, using a custom lambda to map values: ```bicep var example = mapValues({ foo: 'foo' }, val => toUpper(val)) // returns { foo: 'FOO' } ``` * `groupBy`: Create an object with array values from an array, using a grouping condition: ```bicep var example = groupBy(['foo', 'bar', 'baz'], x => substring(x, 0, 1)) // returns { f: [ 'foo' ], b: [ 'bar', 'baz' ] ``` * `shallowMerge`: Perform a shallow merge of input object parameters: ```bicep var example = shallowMerge([{ foo: 'foo' }, { bar: 'bar' }]) // returns { foo: 'foo', bar: 'bar' } ``` 1. Optional indices on lambdas + usage: * `map`: ```bicep var example = map(['a', 'b'], (x, i) => { index: i, val: x }) // returns [ { index: 0, val: 'a' }, { index: 1 val: 'b' } ] ``` * `reduce`: ```bicep var example = reduce([ 2, 3, 7 ], (cur, next, i) => (i % 2 == 0) ? cur + next : cur) // returns 9 ``` * `filter`: ```bicep var example = filter([ 'foo', 'bar', 'baz' ], (val, i) => i < 2 && substring(val, 0, 1) == 'b') // returns [ 'bar' ] ``` Closes #13560 Closes #9244 Closes #1560 Addresses some of the issues described under the following: #2082, #1853, #387 ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13658)
- Loading branch information