Skip to the content.

aggregate

local aggregate = import "github.com/jsonnet-libs/xtd/aggregate.libsonnet"

aggregate implements helper functions to aggregate arrays of objects into objects with arrays.

Example:

local apps = [
  {
    appid: 'id1',
    name: 'yo',
    id: i,
  }
  for i in std.range(0, 10)
];

aggregate.byKeys(apps, ['appid', 'name']);

Output:

{
   "id1": {
      "yo": [
         {
            "appid": "id1",
            "id": 0,
            "name": "yo"
         },
         {
            "appid": "id1",
            "id": 1,
            "name": "yo"
         },
         ...
      ]
   }
}

Index

Fields

fn byKey

byKey(arr, key)

byKey aggregates an array by the value of key

fn byKeys

byKeys(arr, keys)

byKey aggregates an array by iterating over keys, each item in keys nests the aggregate one layer deeper.