Returns a new set with the elements of the second set removed from the first.
Returns: Uniq
- The set with the elements of other set removed from the source set.
Throws:
TypeError
When other is null or undefined.
Param | Description |
---|---|
other | The set whose elements will be removed. |
Example
const uniq_1 = new Uniq([1, 2, 3, 4, 5]);
const uniq_2 = new Uniq([1, 2]);
const difference = uniq_1.difference(uniq_2);
console.log(difference);
// => [Uniq] { 3, 4, 5 }
Returns: Uniq
- The new set.
Example
const uniq = Uniq.empty();
Returns: boolean
- True if all elements of set satisfy predicate.
Throws:
TypeError
When predicate is not a function or a generator function.
Param | Description |
---|---|
predicate | The function to test set elements. |
Example
const uniq_3 = Uniq.of(1, 3, 5);
const allOdds = uniq_3.every(x => x % 2 !== 0);
console.log(allOdds);
// => true
Returns: boolean
- True if any element of set satisfies predicate.
Param | Description |
---|---|
predicate | The function to test set elements. |
Example
const uniq_4 = Uniq.of(1, 2, 3, 4, 5);
const hasEvenNum = uniq_4.exists(x => x % 2 === 0);
console.log(hasEvenNum);
// => true
Returns: Uniq
- The set containing only the elements for which predicate returns true.
Throws:
TypeError
When predicate is not a function or a generator function.
Param | Description |
---|---|
predicate | The function to test set elements. |
Example
const uniq_5 = Uniq.of(1, 2, 3, 4, 5);
const filtered = uniq_5.filter(x => x > 2);
console.log(filtered);
// => [Uniq] { 3, 4, 5 }
Returns: The final state.
Throws:
TypeError
When state is null or undefined. Or folder is not a function or folder is a generator function.
Param | Description |
---|---|
folder | The accumulating function. |
state | The initial state. |
Example
const uniq_6 = Uniq.of(1, 2, 3, 4, 5);
const foldResult = uniq_6.fold((state, elem) => state - elem, 0);
console.log(foldResult);
// => -15
Returns: The final state.
Throws:
TypeError
When state is null or undefined. Or folder is not a function or folder is a generator function.
Param | Description |
---|---|
folder | The accumulating function. |
state | The initial state. |
Example
const uniq_7 = Uniq.of(1, 2, 3, 4, 5);
const foldRightResult = uniq_7.foldRight((elem, state) => elem - state, 0);
console.log(foldRightResult);
// => 3
Returns: Uniq
- The intersection of the sets.
Throws:
TypeError
When others has one or more sources which are not of type Set or Uniq.
Param | Description |
---|---|
...others | One or more of other sets. |
Example
const uniq_8 = Uniq.of(1, 2, 3, 4, 5, 6, 7);
const otherSet_1 = Uniq.of(1, 2, 3, 4);
const otherSet_2 = new Set([3, 4]);
const intersectResult = uniq_8.intersect(otherSet_1, otherSet_2);
console.log(intersectResult);
// => [Uniq] { 3, 4 }
Returns: boolean
- True if the set is empty.
Example
const uniq = Uniq.of(1, 2, 3, 4);
console.log(uniq.isEmpty());
// => false
Returns: True if the source set is a proper subset of the second.
Throws:
TypeError
When second is null or undefined.
Param | Description |
---|---|
second | The second set to test against. |
Example
const uniq_9 = Uniq.of(1, 2, 3);
const uniq_10 = Uniq.of(1, 2, 3, 4);
const isProperSubSet = uniq_9.isProperSubsetOf(uniq_10);
console.log(`uniq_9 is a proper subset of uniq_10: ${isProperSubSet}`);
// => uniq_9 is a proper subset of uniq_10: true
Returns: True if the source set is a proper superset of the second.
Throws:
TypeError
When second is null or undefined.
Param | Description |
---|---|
second | The second set to test against. |
Example
const uniq_11 = Uniq.of(1, 2, 3, 4);
const uniq_12 = Uniq.of(1, 2, 3);
const isProperSuperset = uniq_11.isProperSupersetOf(uniq_12);
console.log(`uniq_11 is a proper superset of uniq_12: ${isProperSuperset}`);
// => uniq_11 is a proper superset of uniq_12: true
Returns: True if the source set is a subset of the second.
Throws:
TypeError
When second is null or undefined.
Param | Description |
---|---|
second | The set to test against. |
Example
const uniq_13 = Uniq.of(1, 2, 3);
const uniq_14 = Uniq.of(1, 2, 3, 4);
const isSubset = uniq_13.isSubsetOf(uniq_14);
console.log(`uniq_13 is a subset of uniq_14: ${isSubset}`);
// => uniq_13 is a subset of uniq_14: true
Returns: True if the source set is a superset of the second.
Throws:
TypeError
When second is null or undefined.
Param | Description |
---|---|
second | The set to test against. |
Example
const uniq_15 = Uniq.of(1,2,3);
const uniq_16 = Uniq.of(1,2,3);
const isSuperset = uniq_15.isSupersetOf(uniq_16);
console.log(`uniq_15 is a superset of uniq_16: ${isSuperset}`);
// => uniq_15 is a superset of uniq_16: true
Returns: Uniq
- A set containing the transformed elements.
Throws:
TypeError
When mapping is not a function or a generator function.
Param | Description |
---|---|
mapping | The function to transform elements of the input set. |
Example
const uniq_17 = Uniq.of(1, 2, 3, 4, 5);
const mappedResult = uniq_17.map(x => x + x);
console.log(mappedResult);
// => [Uniq] { 2, 4, 6, 8, 10 }
Returns: Uniq
- A newly created uniq.
Example
const uniq = Uniq.of(1, 1, 2, 2, 3, 4, 4, 5);
console.log(uniq);
// => [Uniq] { 1, 2, 3, 4, 5 };
Returns: An array containing two split sets.
Throws:
TypeError
When predicate is not a function or a generator function.
Param | Description |
---|---|
predicate | The function to test set elements. |
Returns: The result array.
Example
const uniq = Uniq.of(1, 2, 3);
const array = uniq.toArray();
console.log(array);
// => [ 1, 2, 3 ]
Returns: The result Dict.
Example
const uniq_20 = Uniq.of(1, 2, 3, 4, 5);
const dict = uniq_20.toDict();
console.log(dict);
// [Dict] { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5 }
Returns: The result Map.
Example
const uniq_21 = Uniq.of(1, 2, 3, 4, 5);
const map = uniq_21.toMap();
console.log(map);
// => Map(5) { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5 }
Returns: The result Vec.
Example
const uniq = Uniq.of(1, 2, 3);
const vec = uniq.toVec();
console.log(vec);
// => [ 1, 2, 3 ]
Returns: Uniq
- The union of sets.
Throws:
TypeError
When others has one or more sources which are not of type Set or Uniq.
Param | Description |
---|---|
...others | One or more of other sets. |
Example
const uniq_18 = Uniq.of(1, 2, 3, 4, 5);
const uniq_19 = Uniq.of(11, 12, 13, 14, 15);
const union = uniq_18.union(uniq_19);
console.log(union);
// => [Uniq] { 1, 2, 3, 4, 5, 11, 12, 13, 14, 15 }