You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at #13555, I would like to be able to offer the following workaround, using some made up functions (groupBy & keys). Feels like these would be useful capabilities:
… 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#13560Closes#9244Closes#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)
Looking at #13555, I would like to be able to offer the following workaround, using some made up functions (
groupBy
&keys
). Feels like these would be useful capabilities:The text was updated successfully, but these errors were encountered: