Skip to content

Commit d798ffc

Browse files
authored
Merge pull request #261 from drammock/feat/unique
feat: add unique() function for expressions
2 parents 9792807 + 990affe commit d798ffc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
### Added
9+
10+
- Add support for the `unique()` function in schema expressions.
11+
12+
<!--
13+
### Changed
14+
15+
- A bullet item for the Changed category.
16+
17+
-->
18+
<!--
19+
### Fixed
20+
21+
- A bullet item for the Fixed category.
22+
23+
-->
24+
<!--
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
<!--
31+
### Removed
32+
33+
- A bullet item for the Removed category.
34+
35+
-->
36+
<!--
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->
42+
<!--
43+
### Infrastructure
44+
45+
- A bullet item for the Infrastructure category.
46+
47+
-->

src/schema/expressionLanguage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ export const expressionFunctions = {
9090
}
9191
return null
9292
},
93+
unique: <T>(list: T[]): T[] | null => {
94+
if (list !== null) {
95+
return [...new Set(list)]
96+
}
97+
return null
98+
},
9399
count: <T>(list: T[], val: T): number => {
94100
return list.filter((x) => x === val).length
95101
},

0 commit comments

Comments
 (0)