From abffe2365bd6a1a64e2011b80cdb4eb77c7fce79 Mon Sep 17 00:00:00 2001 From: holroy Date: Sun, 12 Jan 2025 18:24:41 +0100 Subject: [PATCH] Added test and documentation for DQL - unique() Added documentation and some simple tests for the DQL function unique() which was missing. --- docs/docs/reference/functions.md | 8 ++++++++ src/test/function/aggregation.test.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/docs/docs/reference/functions.md b/docs/docs/reference/functions.md index 0908d10b..be7bc75f 100644 --- a/docs/docs/reference/functions.md +++ b/docs/docs/reference/functions.md @@ -512,6 +512,14 @@ filter([1, 2, 3], (x) => x >= 2) = [2, 3] filter(["yes", "no", "yas"], (x) => startswith(x, "y")) = ["yes", "yas"] ``` +### `unique(array)` + +Creates a new array with only unique values. + +```js +unique([1, 3, 7, 3, 1]) => [1, 3, 7] +``` + ### `map(array, func)` Applies the function to each element in the array, returning a list of the mapped results. diff --git a/src/test/function/aggregation.test.ts b/src/test/function/aggregation.test.ts index 4da1986d..c33089d2 100644 --- a/src/test/function/aggregation.test.ts +++ b/src/test/function/aggregation.test.ts @@ -11,6 +11,13 @@ describe("filter()", () => { test("number list", () => expectEvals("filter(list(1, 2, 3), (k) => k >= 2)", [2, 3])); }); +describe("unique()", () => { + test("empty", () => expectEvals("unique([])", [])); + test("single", () => expectEvals("unique([1])", [1])); + test("multiple unique", () => expectEvals("unique([1, 1, 1])", [1])); + test("multiple same", () => expectEvals("unique([1, 3, 7, 3, 1])", [1, 3, 7])); +}); + describe("min()", () => { test("empty", () => expectEvals("min()", null)); test("single", () => expectEvals("min(6)", 6));