namespace HashSet
A type-invariant immutable Set of value type T. In the Set, there are no duplicate values. See the Set documentation and the HashSet API documentation
Companion interface: HashSet<T>
Interfaces
Name | Description |
---|---|
HashSet.Builder<T> | A mutable HashSet builder used to efficiently create new immutable instances. See the Set documentation and the HashSet.Builder API documentation |
HashSet.Context<UT> | A context instance for a HashSet that acts as a factory for every instance of this type of collection. |
HashSet.NonEmpty<T> | A non-empty type-invariant immutable Set of value type T. In the Set, there are no duplicate values. See the Set documentation and the HashSet API documentation |
HashSet.Types | Utility interface that provides higher-kinded types for this collection. |
Static Methods
builder
Returns an empty builder instance for this type of collection and context.
builder
createContext
Returns a new HashSet context instance based on the given options
.
createContext
options
.Definition
createContext<UT>(options?: {
hasher?: Hasher<UT>;
eq?: Eq<UT>;
blockSizeBits?: number;
listContext?:
List.Context
;
}):
HashSet.Context
<UT>;
Type parameters
Name | Description |
---|---|
UT | the upper element type for which the context can create instances |
Parameters
Name | Type | Description |
---|---|---|
options | { hasher?: Hasher<UT>; eq?: Eq<UT>; blockSizeBits?: number; listContext?: List.Context ; } | (optional) an object containing the following properties:<br/. - hasher - (optional) a Hasher instance used to hash the map keys- eq - (optional) an Eq instance used to determine key equality- blockSizeBits: (optional) determines the maximum block size as 2 to the power of blockSizeBits - listContext: (optional) the context to use to create list instances (for collisions) |
defaultContext
Returns the default context for HashSets.
defaultContext
Definition
defaultContext<UT>():
HashSet.Context
<UT>;
Type parameters
Name | Description |
---|---|
UT | the upper element type for which the context can create instances |
empty
Returns the (singleton) empty instance of this type and context with given value type.
empty
from
Returns an immutable set of this collection type and context, containing the given values in source
.
from
source
.Definitions
from<T extends UT>(...sources:
ArrayNonEmpty
<
StreamSource.NonEmpty
<T>>):
WithElem
<Tp, T>['nonEmpty'];
from<T extends UT>(...sources:
ArrayNonEmpty
<
StreamSource
<T>>):
WithElem
<Tp, T>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
T | UT |
Parameters
Name | Type | Description |
---|---|---|
sources | ArrayNonEmpty < StreamSource.NonEmpty <T>> | an array of StreamSource instances containing values |
HashSet.from([1, 2, 3], [4, 5]) // => HashSet.NonEmpty<number>
Overrides
of
Returns an immutable set of this type and context, containing the given values
.
of
values
.Definition
of<T extends UT>(...values:
ArrayNonEmpty
<T>):
WithElem
<Tp, T>['nonEmpty'];
Type parameters
Name | Constraints | Description |
---|---|---|
T | UT |
Parameters
Name | Type | Description |
---|---|---|
values | ArrayNonEmpty <T> | a non-empty array of values |
HashSet.of(1, 2, 3).toArray() // => [1, 2, 3]
Overrides
reducer
Returns a Reducer
that appends received items to an RSet and returns the RSet as a result. When a source
is given, the reducer will first create an RSet from the source, and then append elements to it.
reducer
Reducer
that appends received items to an RSet and returns the RSet as a result. When a source
is given, the reducer will first create an RSet from the source, and then append elements to it.Definition
reducer<T extends UT>(source?:
StreamSource
<T>): Reducer<T,
WithElem
<Tp, T>['normal']>;
Type parameters
Name | Constraints | Description |
---|---|---|
T | UT |
Parameters
Name | Type | Description |
---|---|---|
source | StreamSource <T> | (optional) an initial source of elements to append to |
const someList = SortedSet.of(1, 2, 3);
const result = Stream.range({ start: 20, amount: 5 }).reduce(SortedSet.reducer(someList))
result.toArray() // => [1, 2, 3, 20, 21, 22, 23, 24]
uses an RSet builder under the hood. If the given source
is a RSet in the same context, it will directly call .toBuilder()
.