UNPKG

@cute-dw/core

Version:

This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need

55 lines (54 loc) 3.19 kB
import { Observable } from "rxjs"; import { Predicate } from "../util/function/Predicate"; import { Iterable } from "./Iterable"; export type Element<T> = T | null; /** * The root _immutable_ interface in the collection hierarchy. Methods that modify collections are not defined in this interface, * instead they are defined in the `Collection` or its subinterfaces. A collection represents a group of objects, known as its elements. */ export interface ImmutableCollection<T> extends Iterable<T> { /** Returns an observable object to look after the changes in this collection */ get contentChanged(): Observable<void>; /** Returns the number of elements in this collection. Defined for compatibility with JavaScript's `Array` interface */ get length(): number; /** Returns the number of elements in this collection */ get size(): number; /** Returns true if this collection contains the specified element */ contains(value: Element<T>): boolean; /** Returns true if this collection contains all of the elements in the specified collection */ containsAll(c: Collection<T> | Array<T>): boolean; /** Compares the specified object with this collection for equality */ equals(value: any): boolean; /** Returns the first element in the provided array that satisfies the provided testing function. */ find(predicate: Predicate<Element<T>>): Element<T> | undefined; /** Returns true if this collection contains no elements */ isEmpty(): boolean; /** Returns a sequential `Observable` object with this collection as its source */ stream(): Observable<Element<T>>; /** Returns an array containing all of the elements in this collection */ toArray(): Array<Element<T>>; toJSON(): Array<Element<T>>; toString(): string; } /** * The root _mutable_ interface in the collection hierarchy. A collection represents a group of objects, known as its elements. * Some collections allow duplicate elements and others do not. Some are ordered and others unordered. */ export interface Collection<T> extends ImmutableCollection<T> { /** Ensures that this collection contains the specified element */ add(value: Element<T>): this; /** Ensures that this collection contains the specified element */ append(value: Element<T>): boolean; /** Appends all of the elements in the specified collection to this collection */ appendAll(c: Collection<T> | Array<T>): boolean; /** Removes all of the elements from this collection */ clear(): void; /** Removes a single instance of the specified element from this collection, if it is present */ remove(value: Element<T>): boolean; /** Removes all of this collection's elements that are also contained in the specified collection */ removeAll(c: Collection<T> | Array<T>): boolean; /** Removes all of the elements of this collection that satisfy the given predicate */ removeIf(p: Predicate<Element<T>>): boolean; /** Retains only the elements in this collection that are contained in the specified collection */ retainAll(c: Collection<T> | Array<T>): boolean; }