Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jamashita/lluvia
Collection classes that have the same interface
https://github.com/jamashita/lluvia
array collection map set typescript
Last synced: 24 days ago
JSON representation
Collection classes that have the same interface
- Host: GitHub
- URL: https://github.com/jamashita/lluvia
- Owner: jamashita
- License: mit
- Created: 2021-01-30T15:34:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T03:09:14.000Z (about 2 months ago)
- Last Synced: 2024-10-14T23:53:17.927Z (about 1 month ago)
- Topics: array, collection, map, set, typescript
- Language: TypeScript
- Homepage:
- Size: 3.27 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Lluvia
Collections.
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)[![CI](https://github.com/jamashita/lluvia/actions/workflows/ci.yml/badge.svg)](https://github.com/jamashita/lluvia/actions/workflows/ci.yml)
## Install
```text
yarn add @jamashita/lluvia
```## Prerequisite
```
> node -v
v20.12.2> npm -v
10.5.0> yarn -v
1.22.21
```## Conventional commit
```
git cz
```# Address classes
## (interface) Address\
This interface represents a collection `Set`. It means, Unique values can be stored in this collection instance. If
the value implements the `hashCode()` method from `@jamashita/anden`, the value will be stored by its hash code. In case
of hash code conflicts, the previous value will be overwritten. This interface extends the `ReadonlyAddress`.### `Address.prototype.add(value: V): Address`
Adds the given `value` to the collection.
### (override) `Address.prototype.filter(predicate: NarrowingBinaryPredicate): Address`
### (override) `Address.prototype.filter(predicate: BinaryPredicate): Address`
This is an overridden version of the `ReadonlyAddress.prototype.filter(predicate)`.
### (override) `Address.prototype.map(mapping: Mapping): Address`
This is an overridden version of the `ReadonlyAddress.prototype.map(mapping)`.
### `Address.prototype.remove(value: V): Address`
Removes the value that matches the given `value` from the collection.
## ImmutableAddress
This is an immutable class that implements `Address`. It does not allow adding or removing values from the
collection directly, but instead returns a new instance of the collection with the added or removed values.### `ImmutableAddress.await(address: ReadonlyAddress>): Promise>`
Takes a `ReadonlyAddress>` and returns a single `Promise>` that resolves with a new
instance of `ImmutableAddress` containing the resolved values.### `ImmutableAddress.empty(): ImmutableAddress`
Returns an empty `ImmutableAddress`.
### `ImmutableAdress.of(collection: Collection): ImmutableAddress`
Generates a new instance of `ImmutableAddress` from the given `collection`.
### `ImmutableAdress.ofSet(set: ReadonlySet): ImmutableAddress`
Generates a new instance of `ImmutableAddress` from the given `set`.
### `ImmutableAddress.prototype.add(value: V): ImmutableAddress`
Adds the given `value` to a new instance of `ImmutableAddress`, instead of the current collection instance, and then
returns the new instance.### (override) `ImmutableAddress.prototype.filter(predicate: NarrowingBinaryPredicate): ImmutableAddress`
### (override) `ImmutableAddress.prototype.filter(predicate: BinaryPredicate): ImmutableAddress`
This is an overridden version of the `Address.prototype.filter(predicate)`.
### (override) `ImmutableAddress.prototype.map(mapping: Mapping): ImmutableAddress`
This is an overridden version of the `Address.prototype.map(mapping)`.
### `ImmutableAddress.prototype.remove(value: V): ImmutableAddress`
Creates a new instance of `ImmutableAddress` by removing the value that matches the given `value` from the current
collection instance and then returns the new instance.## MutableAddress
This is a mutable class that implements Address. It allows adding and removing values from the collection.
### `MutableAddress.await(address: ReadonlyAddress>): Promise>`
Takes a `ReadonlyAddress>` and returns a single `Promise>` that resolves with a new
instance of `MutableAddress` containing the resolved values.### `MutableAddress.empty(): MutableAddress`
Returns an empty `MutableAddress`.
### `MutableAdress.of(collection: Collection): MutableAddress`
Generates a new instance of `MutableAddress` from the given `collection`.
### `MutableAdress.ofSet(set: ReadonlySet): MutableAddress`
Generates a new instance of `MutableAddress` from the given `set`.
### `MutableAddress.prototype.add(value: V): this`
Adds the given `value` to the current collection instance and returns the current instance itself.
### (override) `MutableAddress.prototype.filter(predicate: NarrowingBinaryPredicate): MutableAddress`
### (override) `MutableAddress.prototype.filter(predicate: BinaryPredicate): MutableAddress`
This is an overridden version of the `Address.prototype.filter(predicate)`.
### (override) `MutableAddress.prototype.map(mapping: Mapping): MutableAddress`
This is an overridden version of the `Address.prototype.map(mapping)`.
### `MutableAddress.prototype.remove(value: V): this`
Removes the value that matches the given `value` from the collection and returns the current instance itself.
## (interface) ReadonlyAddress\
This interface represents a read-only version of a `Set` collection, meaning that values cannot be added or modified
within the collection instance. If the value implements the `hashCode()` method from `@jamashita/anden`, the value will
be stored based on its hash code. In case of hash code conflicts, the previous value will be overwritten. This interface
extends `Collection`.### (override) `ReadonlyAddress.prototype.filter(predicate: NarrowingBinaryPredicate): ReadonlyAddress`
### (override) `ReadonlyAddress.prototype.filter(predicate: BinaryPredicate): ReadonlyAddress`
This is an overridden version of the `Collection.prototype.filter(predicate)`.
### (override) `ReadonlyAddress.prototype.map(mapping: Mapping): ReadonlyAddress`
This is an overridden version of the `Collection.prototype.map(mapping)`.
### `ReadonlyAddress.prototype.has(value: :V): boolean`
Returns `true` if the given `value` is contained in the collection.
### `ReadonlyAddress.prototype.toSet(): Set`
Returns a new `Set` containing all the values in the collection.
# Collection classes
## (interface) Collection
The common interface for `Sequence`, `Dictionary` and `Address`. This interface provides common methods for
manipulating multiple data. `K` represents the key of the collection and `V` represents the value of the collection.
This interface also extends `Iterable<[K, V]>`.### (override) `Collection.prototype[Symbol.iterator](): IterableIterator<[K, V]>`
This method is invoked by the `for-of` loop. It allows iteration through the key-value pairs of the collection as
tuples.### `Collection.prototype.contains(value: V): boolean`
Returns `true` if the given `value` is contained within this collection instance.
### `Collection.prototype.every(predicate: Predicate): boolean`
Returns `true` if every item in the collection satisfies the given `predicate`.
### `Collection.prototype.filter(predicate: NarrowingBinaryPredicate): Collection`
### `Collection.prototype.filter(predicate: BinaryPredicate): Collection`
Returns a new collection containing only the items that satisfy the given `predicate`. The type of items in the new
collection depends on whether the `predicate` is narrowing or not.### `Collection.prototype.find(predicate: NarrowingBinaryPredicate): Nulable`
### `Collection.prototype.find(predicate: BinaryPredicate): Nulable`
Returns the first value that satisfies the given `predicate`. If there are no items that satisfy the `predicate`,
returns `null`.### `Collection.prototype.forEach(foreach: ForEach): void`
Iterates through each item and applies the provided `foreach` once.
### `Collection.prototype.get(key: K): Nullable`
Returns the value of the specified `key`. If there is no value, return `null`.
### `Collection.prototype.isEmpty(): boolean`
Returns `true` if this collection has no items.
### `Collection.prototype.iterator(): IterableIterator<[K, V]>`
Returns an iterator that iterates over the key-value pairs in the collection.
### `Collection.prototype.map(mapping: Mapping): Collection`
Applies the provided `mapping` to every item and updates the values to the returned result of the `mapping`.
### `Collection.prototype.size(): number`
Returns the number of items in the collection.
### `Collection.prototype.some(predicate: BinaryPredicate): boolean`
Returns `true` if at least one item in the collection satisfies the given `predicate`.
### `Collection.prototype.values(): IterableIterator`
Returns an iterator that iterates over the values in the collection.
# Dictionary classes
## (interface) Dictionary\
This interface represents a collection `Map`. If the key implements `hasCode()` method
from `@jamashita/anden`, the value will be able to stored by its hash code.
In case of hash codes conflict, the previous value will be overwritten. This interface extends `ReadonlyDictionary`.### (override) `Dictionary.prototype.filter(predicate: NarrowingBinaryPredicate): Dictionary`
### (override) `Dictionary.prototype.filter(predicate: BinaryPredicate): Dictionary`
This is an overridden version of the `ReadonlyDictionary.prototype.filter(predicate)`.
### (override) `Dictionary.prototype.map(mapping: Mapping): Dictionary`
This is an overridden version of the `ReadonlyDictionary.prototype.map(mapping)`.
### `Dictionary.prototype.remove(key: K): Dictionary`
Removes the value that matches the given `key` from the collection.
### `Dictionary.prototype.set(key: K, value: V): Dictionary`
Sets or updates the given `value` to the specified `key` in the collection.
## ImmutableDictionary\
This is an immutable class that implements `Dictionary`. It does not allow adding or removing entries from the
collection directly, but instead returns a new instance of the collection with the added or removed entries.### `ImmutableDictionary.await(dictionary: ReadonlyDictionary>): Promise>`
Takes a `ReadonlyDictionary>` and return a single `Promise>` that resolves
with a new instance of `ImmutableDictionary` containing the resolved values.### `ImmutableDictionary.empty(): ImmutableDictionary`
Returns an empty `ImmutableDictionary`.
### `ImmutableDictionary.of(collection: Collection): ImmutableDictionary`
Generates a new instance of `ImmutableDictionary` from the given `collection`.
### `ImmutableAdress.ofMap(map: ReadonlyMap): ImmutableDictionary`
Generates a new instance of `ImmutableDictionary` from the given `map`.
### (override) `ImmutableDictionary.prototype.filter(predicate: NarrowingBinaryPredicate): ImmutableDictionary`
### (override) `ImmutableDictionary.prototype.filter(predicate: BinaryPredicate): ImmutableDictionary`
This is an overridden version of the `Dictionary.prototype.filter(predicate)`.
### (override) `ImmutableDictionary.prototype.map(mapping: Mapping): ImmutableDictionary`
This is an overridden version of the `Dictionary.prototype.map(mapping)`.
### `ImmutableDictionary.prototype.remove(key: K): ImmutableDictionary`
Creates a new instance of `ImmutableDictionary` by removing the entry that matches the given `key` from the
current collection instance and then returns the new instance.### `ImmutableDictionary.prototype.set(key: K, value: V): ImmutableDictionary`
Sets or updates the given `value` for the specified `key` in a new instance of `ImmutableDictionary`, instead of
the current collection instance, and returns the new instance.## MutableDictionary\
This is an mutable class that implements `Dictionary`.
### `MutableDictionary.await(dictionary: ReadonlyDictionary>): Promise>`
Takes a `ReadonlyDictionary>` and returns a single `Promise>` that resolves
with a new instance of `MutableDictionary` containing the resolved values.### `MutableDictionary.empty(): MutableDictionary`
Returns an empty `MutableDictionary`.
### `MutableDictionary.of(collection: Collection): MutableDictionary`
Generates a new instance of `MutableDictionary` from the given `collection`.
### `MutableAdress.ofMap(map: ReadonlyMap): MutableDictionary`
Generates a new instance of `MutableDictionary` from the given `map`.
### (override) `MutableDictionary.prototype.filter(predicate: NarrowingBinaryPredicate): MutableDictionary`
### (override) `MutableDictionary.prototype.filter(predicate: BinaryPredicate): MutableDictionary`
This is an overridden version of the `Dictionary.prototype.filter(predicate)`.
### (override) `MutableDictionary.prototype.map(mapping: Mapping): MutableDictionary`
This is an overridden version of the `Dictionary.prototype.map(mapping)`.
### `MutableDictionary.prototype.remove(key: K): this`
Removes entry that matches the given `key` from the collection and returns the current instance itself.
### `MutableDictionary.prototype.set(key: K, value: V): this`
Sets or updates the given `value` for the specified `key` to the current collection instance and returns the current
instance itself.### (interface) ReadonlyDictionary\
This interface represents a read-only version of a `Map` collection, which means that values cannot be added or
modified within the collection instance. If the value implements `hasCode()` method from `@jamashita/anden`, the entry
will be able to stored by its hash code. In case of hash codes conflict, the previous entry will be overwritten. This
interface extends `Collection`.### (override) `ReadonlyDictionary.prototype.filter(predicate: NarrowingBinaryPredicate): ReadonlyDictionary`
### (override) `ReadonlyDictionary.prototype.filter(predicate: BinaryPredicate): ReadonlyDictionary`
This is an overridden version of the `Collection.prototype.filter(predicate)`.
### `ReadonlyDictionary.prototype.has(key: K): boolean`
Returns `true` if the given `key` is contained in the collection.
### `ReadonlyDictionary.prototype.keys(): IterableIterator`
Returns an iterator that iterates over the keys in the collection.
### (override) `ReadonlyDictionary.prototype.map(mapping: Mapping): ReadonlyDictionary`
This is an overridden version of the `Collection.prototype.map(mapping)`.
### `ReadonlyDictionary.prototype.toMap(): Map`
Returns a new `Map` containing all the entries in the collection.
# Sequence classes
## ImmutableSequence\
This is an immutable class that implements `Sequence`.
### `ImmutableSequecne.await(sequence: ReadonlySequence>): Promise>`
Takes a `ReadonlySequence>` and return a single `Promise>`.
### `ImmutableSequence.empty(): ImmutableSequence`
Returns an empty `ImmutableSequence`.
### `ImmutableSequence.of(collection: Collection): ImmutableSequence`
Generates a new instance of `ImmutableSequence` from the given `collection`.
### `ImmutableSequence.ofArray(array: ReadonlyArray): ImmutableSequence`
Generates a new instance of `MutableSequence` from the given `array`.
### `ImmutableSequence.prototype.add(value: V): ImmutableSequence`
Adds the given `value` to a new instance of `ImmutableSequence`, instead of the current collection instance, and then
returns the new instance.### (override) `ImmutableSequence.prototype.filter(predicate: NarrowingBinaryPredicate): ImmutableSequence`
### (override) `ImmutableSequence.prototype.filter(predicate: BinaryPredicate): ImmutableSequence`
This is an overridden version of the `Sequence.prototype.filter(predicate)`.
### (override) `ImmutableSequence.prototype.map(mapping: Mapping): ImmutableSequence`
This is an overridden version of the `Sequence.prototype.map(mapping)`.
### `ImmutableSequence.prototype.remove(key: number): ImmutableSequence`
Creates a new instance of `ImmutableSequence` by removing the value that matches the given `key` from the
current collection instance and then returns the new instance.### `ImmutableSequecne.prototype.set(key, number, value: V): ImmutableSequence`
Sets or updates the given `value` for the specified `key` in a new instance of `ImmutableSequence` instead of the
## MutableSequence\
This is an mutable class that implements `Sequence`.
### `MutableSequecne.await(sequence: ReadonlySequence>): Promise>`
Takes a `ReadonlySequence>` and return a single `Promise>`.
### `MutableSequence.empty(): MutableSequence`
Returns an empty `MutableSequence`.
### `MutableSequence.of(collection: Collection): MutableSequence`
Generates a new instance of `MutableSequence` from the given `collection`.
### `MutableSequence.ofArray(array: ReadonlyArray): MutableSequence`
Generates a new instance of `MutableSequence` from the given `array`.
### `MutableSequence.prototype.add(value: V): this`
Adds the given `value` to the current collection instance and returns the current instance itself.
### (override) `MutableSequence.prototype.filter(predicate: NarrowingBinaryPredicate): MutableSequence`
### (override) `MutableSequence.prototype.filter(predicate: BinaryPredicate): MutableSequence`
This is an overridden version of the `Sequence.prototype.filter(predicate)`.
### (override) `MutableSequence.prototype.map(mapping: Mapping): MutableSequence`
This is an overridden version of the `Sequence.prototype.map(mapping)`.
### `MutableSequence.prototype.remove(key: number): this`
Removes value that matches the given `value` from the collection and returns the current instance itself.
### `MutableSequecne.prototype.set(key, number, value: V): MutableSequence`
Sets or updates the given `value` for the specified `key` to the current collection instance and returns the current
instance itself.## (interface) ReadonlySequence\
This interface represents a read-only version of a `Array` collection, which means that values cannot be added or
modified within the collection instance. This interface extends `Collection`.### (override) `ReadonlySequence.prototype.filter(predicate: NarrowingBinaryPredicate): ReadonlySequence