FuncType - v1.21.0
    Preparing search index...

    Interface Set<A>

    Immutable Set. Covariant in A (<out A>) — while Scala's Set[A] is nominally invariant, functype's Set follows the same pragmatic covariance pattern as List: element-query methods (contains, has, remove) accept unknown, and additions widen via <B>(B) => Set<A | B>. reduce/reduceRight follow Scala's reduce[B >: A] pattern with a default B = A.

    interface Set<out A> {
        _tag: "Set";
        "[toStringTag]": string;
        filter: (p: (a: A) => boolean) => Set<A>;
        filterNot: (p: (a: A) => boolean) => Set<A>;
        flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>;
        fold: <B>(initial: B, fn: (acc: B, a: A) => B) => B;
        isEmpty: boolean;
        map: <B>(f: (a: A) => B) => Set<B>;
        mapAsync: <B>(
            f: (a: A) => PromiseLike<B>,
            options?: ConcurrencyOptions,
        ) => Promise<Set<B>>;
        remove: (value: unknown) => Set<A>;
        size: number;
        toArray: <B = A>() => B[];
        toList: () => List<A>;
        toSet: () => Set<A>;
        toString: () => string;
        get head(): A | undefined;
        get headOption(): Option<A>;
        get init(): Self;
        get last(): A | undefined;
        get lastOption(): Option<A>;
        get tail(): Self;
        add<B>(value: B): Set<A | B>;
        ap<B extends unknown>(ff: Applicative<(value: A) => B>): Applicative<B>;
        contains(value: unknown): boolean;
        count(p: (x: A) => boolean): number;
        difference(other: Iterable<unknown>): Set<A>;
        drop(n: number): FunctypeCollection;
        dropRight(n: number): FunctypeCollection;
        dropWhile(p: (a: A) => boolean): FunctypeCollection;
        every(p: (a: A) => boolean): boolean;
        exists(p: (a: A) => boolean): boolean;
        find(p: (a: A) => boolean): Option<A>;
        flatMapAsync<B extends unknown>(
            f: (value: A) => PromiseLike<Iterable<B, any, any>>,
            options?: ConcurrencyOptions,
        ): PromiseLike<FunctypeCollection<B, "Set">>;
        flatten<B>(): FunctypeCollection;
        foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
        foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
        forEach(f: (a: A) => void): void;
        has(value: unknown): boolean;
        intersection(other: Iterable<unknown>): Set<A>;
        isDisjointFrom(other: Iterable<unknown>): boolean;
        isSubsetOf(other: Iterable<unknown>): boolean;
        isSupersetOf(other: Iterable<unknown>): boolean;
        pipe<U extends unknown>(f: (value: A[]) => U): U;
        reduce<B = A>(
            op: (b: Widen<A, B>, a: Widen<A, B>) => Widen<A, B>,
        ): Widen<A, B>;
        reduceRight<B = A>(
            op: (b: Widen<A, B>, a: Widen<A, B>) => Widen<A, B>,
        ): Widen<A, B>;
        serialize(): SerializationMethods<A>;
        symmetricDifference<B>(other: Iterable<B>): Set<A | B>;
        take(n: number): FunctypeCollection;
        takeRight(n: number): FunctypeCollection;
        takeWhile(p: (a: A) => boolean): FunctypeCollection;
        toJSON(): SerializableEnvelope;
        toValue(): { _tag: "Set"; value: A[] };
        union<B>(other: Iterable<B>): Set<A | B>;
    }

    Type Parameters

    • out A

    Hierarchy (View Summary)

    Index
    _tag: "Set"
    "[toStringTag]": string
    filter: (p: (a: A) => boolean) => Set<A>
    filterNot: (p: (a: A) => boolean) => Set<A>
    flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>
    fold: <B>(initial: B, fn: (acc: B, a: A) => B) => B

    Left-associative fold over all elements using an initial value and combining function. Unlike foldLeft (which is curried), this provides a convenient uncurried signature.

    Type Declaration

      • <B>(initial: B, fn: (acc: B, a: A) => B): B
      • Type Parameters

        • B

        Parameters

        • initial: B

          The initial accumulator value

        • fn: (acc: B, a: A) => B

          A function that combines the accumulator with each element

        Returns B

        The final accumulated value

    List([1, 2, 3]).fold(0, (acc, x) => acc + x) // 6
    
    isEmpty: boolean
    map: <B>(f: (a: A) => B) => Set<B>
    mapAsync: <B>(
        f: (a: A) => PromiseLike<B>,
        options?: ConcurrencyOptions,
    ) => Promise<Set<B>>

    Async map: awaits f for each element and collects the results into a Set, so equal results collapse into one. Runs one call at a time by default; pass { concurrency: n } to allow up to n at once, or "unbounded". A rejection rejects the result, and no further calls start.

    remove: (value: unknown) => Set<A>
    size: number
    toArray: <B = A>() => B[]

    Converts the collection to an array.

    toList: () => List<A>
    toSet: () => Set<A>
    toString: () => string
    • get head(): A | undefined

      Gets the first element of the collection.

      Returns A | undefined

    • get headOption(): Option<A>

      Gets the first element wrapped in Option.

      Returns Option<A>

    • get init(): Self

      Gets all elements except the last.

      Returns Self

    • get last(): A | undefined

      Gets the last element of the collection.

      Returns A | undefined

    • get lastOption(): Option<A>

      Gets the last element wrapped in Option.

      Returns Option<A>

    • get tail(): Self

      Gets all elements except the first.

      Returns Self

    • Type Parameters

      • B

      Parameters

      • value: B

      Returns Set<A | B>

    • Counts elements that satisfy the predicate. For single-value containers: returns 0 or 1 For collections: returns the count of matching elements

      Parameters

      • p: (x: A) => boolean

      Returns number

    • Elements in this set and not in other.

      Parameters

      • other: Iterable<unknown>

      Returns Set<A>

    • Tests whether every element satisfies the predicate. True for an empty collection. Stops at the first element that fails. The counterpart of exists.

      Parameters

      • p: (a: A) => boolean

      Returns boolean

      List([1, 2, 3]).every((x) => x > 0) // true
      List<number>([]).every((x) => x > 0) // true
    • Tests whether any element satisfies the predicate. For single-value containers: tests the single value For collections: returns true if any element matches

      Parameters

      • p: (a: A) => boolean

      Returns boolean

    • Finds the first element that satisfies the predicate. For single-value containers: returns Some(value) if predicate matches, None otherwise For collections: returns the first matching element wrapped in Option

      Parameters

      • p: (a: A) => boolean

      Returns Option<A>

    • Async flatMap. options.concurrency caps how many calls of f run at once: 1 runs them in order, one after another; "unbounded" starts them all together. Results keep input order either way. The default depends on the collection: List starts them all; Set runs them in order.

      Type Parameters

      • B extends unknown

      Parameters

      Returns PromiseLike<FunctypeCollection<B, "Set">>

    • Left-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (b: B, a: A) => B) => B

      A function that takes an operation to apply

    • Right-associative fold using the provided zero value and operation

      Type Parameters

      • B

      Parameters

      • z: B

        Zero/identity value

      Returns (op: (a: A, b: B) => B) => B

      A function that takes an operation to apply

    • Applies an effect function to each element. For single-value containers: applies to the value if present For collections: applies to each element

      Parameters

      • f: (a: A) => void

      Returns void

    • Parameters

      • value: unknown

      Returns boolean

    • Elements in both this set and other, in this set's order (native intersection follows the smaller set's).

      Parameters

      • other: Iterable<unknown>

      Returns Set<A>

    • True if this set and other share no element.

      Parameters

      • other: Iterable<unknown>

      Returns boolean

    • True if every element of this set is in other. True for an empty set.

      Parameters

      • other: Iterable<unknown>

      Returns boolean

    • True if every element of other is in this set.

      Parameters

      • other: Iterable<unknown>

      Returns boolean

    • Pipes the value through the provided function

      Type Parameters

      • U extends unknown

        The return type of the function

      Parameters

      • f: (value: A[]) => U

        The function to apply to the value

      Returns U

      The result of applying the function to the value

    • Elements in exactly one of this set and other.

      Type Parameters

      • B

      Parameters

      • other: Iterable<B>

      Returns Set<A | B>

    • Custom JSON serialization. Returns the canonical @functype-marked envelope object so native JSON.stringify (and the rest of the JSON toJSON protocol) emits a round-trip-able shape that Serialization.deserialize can reconstruct.

      Added in 1.2.0. Concrete types narrow the return to their specific marker/tag literals.

      Returns SerializableEnvelope

    • Elements in this set or other. other can be any iterable: an array, a native Set or a functype Set. Like every Set method, it compares elements as has does: by SameValueZero, so objects by identity and NaN equal to NaN.

      Type Parameters

      • B

      Parameters

      • other: Iterable<B>

      Returns Set<A | B>

      Set([1, 2]).union([2, 3]) // Set([1, 2, 3])