Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1022 Bytes

aggregate.md

File metadata and controls

74 lines (55 loc) · 1022 Bytes
permalink
/aggregate/

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.