Nav

groupBy

groupBy(Array<T>, (item: T, index: Number) → R): { (R): Array<T> }

Partitions an Array into a Object that contains Arrays, according to the discriminator function (a lambda) that you define.

The lambda is invoked with three parameters: value, key, and index. If these parameters are not named, the value is defined by default as $, the key $$ and the index $$$.

Transform

        
     
1
2
3
4
%dw 2.0
output application/json
---
"language": payload.langs groupBy $.language
Input

        
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
  "langs": [
    {
      "name": "Foo",
      "language": "Java"
    },
    {
      "name": "Bar",
      "language": "Scala"
    },
    {
      "name": "FooBar",
      "language": "Java"
    }
  ]
}
Output

        
     
1
2
3
4
5
6
7
8
9
10
11
{
  "language": {
    "Scala": [
        {"name":"Bar", "language":"Scala"}
      ],
    "Java": [
        {"name":"Foo", "language":"Java"},
        {"name":"FooBar", "language":"Java"}
      ]
  }
}
groupBy({ (K)?: V }, (value: V, key: K) → R): { (R): Array<T> }

Partitions an Object into a Object that contains Arrays, according to the discriminator lambda you define.

The lambda is invoked with two parameters: value and the key.

groupBy(Null, (Nothing, Nothing) → Any): Null

Helper function that allows groupBy to work with null values.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+