Skip to content

Commit

Permalink
Added test and documentation for DQL - unique()
Browse files Browse the repository at this point in the history
Added documentation and some simple tests for the DQL function unique() which was missing.
  • Loading branch information
holroy committed Jan 12, 2025
1 parent c805c10 commit abffe23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/docs/reference/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/test/function/aggregation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit abffe23

Please sign in to comment.