New Functions
groupBy(expr)— Group array elements by a derived key expression,
producing a map of key to matching elements.
[{"name": "Alice", "dept": "eng"}, {"name": "Bob", "dept": "eng"}, {"name":
"Carol", "dept": "sales"}].groupBy(dept)
// {"eng": [...], "sales": [...]}
reduce(expr, init, update)— Fold an array into a single value using an
accumulator ($acc).
[1, 2, 3, 4].reduce($this, 0, $acc + $this)
// 10
mapValues(expr)— Transform all values of a map/object while preserving
keys.
{"a": 1, "b": 2, "c": 3}.mapValues($this * 2)
// {"a": 2, "b": 4, "c": 6}
New Iteration Variable: $key
All iteration expressions now expose a $key variable — the current index
(for arrays) or key name (for maps).
Supported in: filter, map, each, sortBy, groupBy, any, all,
count, reduce, mapValues, search, and recursive descent.
[10, 20, 30].map($key)
// [0, 1, 2]
[10, 20, 30].filter($key >= 1)
// [20, 30]
{"a": 1, "b": 2}.mapValues($key)
// {"a": "a", "b": "b"}
[10, 20, 30].map($key + $this)
// [10, 21, 32]
Full Changelog: v3.8.1...v3.9.0