Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
 Set.difference
 Set.intersection
 Set.union
 Set.symmetricDifference
 Set.isSubsetOf
 Set.isSupersetOf
 Set.isDisjointFrom
 Set.toArray
  • Loading branch information
andriijas committed Oct 15, 2024
1 parent 0de657a commit a2e1851
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Core__Set.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ type t<'a> = Js.Set.t<'a>
@send external forEach: (t<'a>, 'a => unit) => unit = "forEach"

@send external values: t<'a> => Core__Iterator.t<'a> = "values"

@send external difference: (t<'a>, t<'a>) => t<'a> = "difference"
@send external intersection: (t<'a>, t<'a>) => t<'a> = "intersection"
@send external union: (t<'a>, t<'a>) => t<'a> = "union"
@send external symmetricDifference: (t<'a>, t<'a>) => t<'a> = "symmetricDifference"
@send external isSubsetOf: (t<'a>, t<'a>) => bool = "isSubsetOf"
@send external isSupersetOf: (t<'a>, t<'a>) => bool = "isSupersetOf"
@send external isDisjointFrom: (t<'a>, t<'a>) => bool = "isDisjointFrom"

external toArray: t<'a> => array<'a> = "Array.from"
95 changes: 95 additions & 0 deletions src/Core__Set.resi
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,98 @@ Console.log(set->Set.values->Iterator.toArray)
*/
@send
external values: t<'a> => Core__Iterator.t<'a> = "values"

/**
Returns a new set with the values of the set that are not in the other set.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "orange", "banana"])
let set2 = Set.fromArray(["apple", "banana", "pear"])
set1->Set.difference(set2) // Set.fromArray(["orange"])
```
*/
@send external difference: (t<'a>, t<'a>) => t<'a> = "difference"

/**
Returns a new set with the values containing the values which are in either the set, but not in both.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "orange", "banana"])
let set2 = Set.fromArray(["apple", "banana", "pear"])
set1->Set.symmetricDifference(set2) // Set.fromArray(["orange", "pear"])
```
*/
@send external symmetricDifference: (t<'a>, t<'a>) => t<'a> = "symmetricDifference"

/**
Returns a new set with the values containing the values which are in both the set and the other set.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "orange", "banana"])
let set2 = Set.fromArray(["apple", "banana", "pear"])
set1->Set.intersection(set2) // Set.fromArray(["apple", "banana"])
```
*/
@send external intersection: (t<'a>, t<'a>) => t<'a> = "intersection"

/**
Returns a bool indicating if this set has no elements in common with the given set.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "orange", "banana"])
let set2 = Set.fromArray(["kiwi", "melon", "pear"])
set1->Set.isDisjointFrom(set2) // true
```
*/
@send external isDisjointFrom: (t<'a>, t<'a>) => bool = "isDisjointFrom"

/**
Returns a bool indicating if the all values in the set are in the given set.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "banana"])
let set2 = Set.fromArray(["apple", "banana", "pear"])
set1->Set.isSubsetOf(set2) // true
*/
@send external isSubsetOf: (t<'a>, t<'a>) => bool = "isSubsetOf"

/**
Returns a bool indicating if the all values in the given set are in the set.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "banana", "pear"])
let set2 = Set.fromArray(["apple", "banana"])
set1->Set.isSupersetOf(set2) // true
```
*/
@send external isSupersetOf: (t<'a>, t<'a>) => bool = "isSupersetOf"

/**
Returns a new set with the values of the set that are in both the set and the other set.
## Examples
```rescript
let set1 = Set.fromArray(["apple", "orange", "banana"])
let set2 = Set.fromArray(["apple", "banana", "pear"])
set1->Set.union(set2) // Set.fromArray(["apple", "orange", "banana", "pear"])
```
*/
@send external union: (t<'a>, t<'a>) => t<'a> = "union"

/**
`toArray(set)` returns an array of all values of the set.
## Examples
```rescript
let set = Set.fromArray(["apple", "orange", "apple", "banana"])
set->Set.toArray // ["apple", "orange", "banana"]
```
*/
external toArray: t<'a> => array<'a> = "Array.from"

0 comments on commit a2e1851

Please sign in to comment.