Skip to content

Commit a2e1851

Browse files
committed
Add
Set.difference Set.intersection Set.union Set.symmetricDifference Set.isSubsetOf Set.isSupersetOf Set.isDisjointFrom Set.toArray
1 parent 0de657a commit a2e1851

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

src/Core__Set.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ type t<'a> = Js.Set.t<'a>
1515
@send external forEach: (t<'a>, 'a => unit) => unit = "forEach"
1616

1717
@send external values: t<'a> => Core__Iterator.t<'a> = "values"
18+
19+
@send external difference: (t<'a>, t<'a>) => t<'a> = "difference"
20+
@send external intersection: (t<'a>, t<'a>) => t<'a> = "intersection"
21+
@send external union: (t<'a>, t<'a>) => t<'a> = "union"
22+
@send external symmetricDifference: (t<'a>, t<'a>) => t<'a> = "symmetricDifference"
23+
@send external isSubsetOf: (t<'a>, t<'a>) => bool = "isSubsetOf"
24+
@send external isSupersetOf: (t<'a>, t<'a>) => bool = "isSupersetOf"
25+
@send external isDisjointFrom: (t<'a>, t<'a>) => bool = "isDisjointFrom"
26+
27+
external toArray: t<'a> => array<'a> = "Array.from"

src/Core__Set.resi

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,98 @@ Console.log(set->Set.values->Iterator.toArray)
183183
*/
184184
@send
185185
external values: t<'a> => Core__Iterator.t<'a> = "values"
186+
187+
/**
188+
Returns a new set with the values of the set that are not in the other set.
189+
190+
## Examples
191+
```rescript
192+
let set1 = Set.fromArray(["apple", "orange", "banana"])
193+
let set2 = Set.fromArray(["apple", "banana", "pear"])
194+
set1->Set.difference(set2) // Set.fromArray(["orange"])
195+
```
196+
*/
197+
@send external difference: (t<'a>, t<'a>) => t<'a> = "difference"
198+
199+
/**
200+
Returns a new set with the values containing the values which are in either the set, but not in both.
201+
202+
## Examples
203+
```rescript
204+
let set1 = Set.fromArray(["apple", "orange", "banana"])
205+
let set2 = Set.fromArray(["apple", "banana", "pear"])
206+
set1->Set.symmetricDifference(set2) // Set.fromArray(["orange", "pear"])
207+
```
208+
209+
*/
210+
@send external symmetricDifference: (t<'a>, t<'a>) => t<'a> = "symmetricDifference"
211+
212+
/**
213+
Returns a new set with the values containing the values which are in both the set and the other set.
214+
215+
## Examples
216+
```rescript
217+
let set1 = Set.fromArray(["apple", "orange", "banana"])
218+
let set2 = Set.fromArray(["apple", "banana", "pear"])
219+
set1->Set.intersection(set2) // Set.fromArray(["apple", "banana"])
220+
```
221+
*/
222+
@send external intersection: (t<'a>, t<'a>) => t<'a> = "intersection"
223+
224+
/**
225+
Returns a bool indicating if this set has no elements in common with the given set.
226+
227+
## Examples
228+
```rescript
229+
let set1 = Set.fromArray(["apple", "orange", "banana"])
230+
let set2 = Set.fromArray(["kiwi", "melon", "pear"])
231+
set1->Set.isDisjointFrom(set2) // true
232+
```
233+
*/
234+
@send external isDisjointFrom: (t<'a>, t<'a>) => bool = "isDisjointFrom"
235+
236+
/**
237+
Returns a bool indicating if the all values in the set are in the given set.
238+
239+
## Examples
240+
```rescript
241+
let set1 = Set.fromArray(["apple", "banana"])
242+
let set2 = Set.fromArray(["apple", "banana", "pear"])
243+
set1->Set.isSubsetOf(set2) // true
244+
*/
245+
@send external isSubsetOf: (t<'a>, t<'a>) => bool = "isSubsetOf"
246+
247+
/**
248+
Returns a bool indicating if the all values in the given set are in the set.
249+
250+
## Examples
251+
```rescript
252+
let set1 = Set.fromArray(["apple", "banana", "pear"])
253+
let set2 = Set.fromArray(["apple", "banana"])
254+
set1->Set.isSupersetOf(set2) // true
255+
```
256+
*/
257+
@send external isSupersetOf: (t<'a>, t<'a>) => bool = "isSupersetOf"
258+
259+
/**
260+
Returns a new set with the values of the set that are in both the set and the other set.
261+
262+
## Examples
263+
```rescript
264+
let set1 = Set.fromArray(["apple", "orange", "banana"])
265+
let set2 = Set.fromArray(["apple", "banana", "pear"])
266+
set1->Set.union(set2) // Set.fromArray(["apple", "orange", "banana", "pear"])
267+
```
268+
*/
269+
@send external union: (t<'a>, t<'a>) => t<'a> = "union"
270+
271+
/**
272+
`toArray(set)` returns an array of all values of the set.
273+
274+
## Examples
275+
```rescript
276+
let set = Set.fromArray(["apple", "orange", "apple", "banana"])
277+
set->Set.toArray // ["apple", "orange", "banana"]
278+
```
279+
*/
280+
external toArray: t<'a> => array<'a> = "Array.from"

0 commit comments

Comments
 (0)