collections module
Higher-level array/object helpers for grouping and partitioning.
Overview
Use collections when you need to split, group, or clean arrays. Functions are pure and return new arrays.
API
groupBy(items, key)→ map-like object keyed by property.partition(items, key, value)→ [matches, rest].compact(items)→ removes falsy values.
Keys can be property names or paths supported by the runtime.
Examples
javascript
const collections = use("collections");
function main() { const users = [ { id: 1, role: "admin" }, { id: 2, role: "mod" }, { id: 3, role: "mod" }, ]; const grouped = collections.groupBy(users, "role"); ctx.reply("mods=" + grouped.mod.length + "; admins=" + grouped.admin.length);}javascript
const collections = use("collections");
function main() { const nums = [0, 1, 2, null, 3, undefined]; ctx.reply("compact: " + collections.compact(nums).join(", "));}