Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ISet<T>

A generic interface for set-like implementations.

Type parameters

  • T

    the item type

Hierarchy

Implemented by

Index

Methods

__@iterator

  • __@iterator(): Iterator<T>
  • Returns Iterator<T>

__computed

  • __computed(): string
  • Used by the node REPL to display values. Most of the time should be the same as toString()

    Returns string

add

addAll

allMatch

  • allMatch(predicate: function): boolean
  • Returns true if the predicate returns true for all the elements in the collection.

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns boolean

anyMatch

  • anyMatch(predicate: function): boolean
  • Returns true if there the predicate returns true for any element in the collection.

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns boolean

arrangeBy

contains

diff

equals

  • Two objects are equal if they represent the same value, regardless of whether they are the same object physically in memory.

    Parameters

    Returns boolean

filter

  • Call a predicate for each element in the collection, build a new collection holding only the elements for which the predicate returned true.

    Type parameters

    • U: T

    Parameters

    • fn: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns Collection<U>

  • Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns Collection<T>

flatMap

  • flatMap<U>(mapper: function): ISet<U>
  • Calls the function you give for each item in the set, your function returns a set, all the sets are merged.

    Type parameters

    • U

    Parameters

    Returns ISet<U>

fold

  • fold(zero: T, fn: function): T
  • Reduces the collection to a single value using the associative binary function you give. Since the function is associative, order of application doesn't matter.

    Example:

    HashSet.of(1,2,3).fold(0, (a,b) => a + b);
    => 6
    

    Parameters

    • zero: T
    • fn: function
        • (v1: T, v2: T): T
        • Parameters

          • v1: T
          • v2: T

          Returns T

    Returns T

foldLeft

  • foldLeft<U>(zero: U, fn: function): U
  • Reduces the collection to a single value. Left-associative.

    Example:

    Vector.of("a", "b", "c").foldLeft("!", (xs,x) => x+xs);
    => "cba!"
    

    Type parameters

    • U

    Parameters

    • zero: U

      The initial value

    • fn: function

      A function taking the previous value and the current collection item, and returning an updated value.

        • (soFar: U, cur: T): U
        • Parameters

          • soFar: U
          • cur: T

          Returns U

    Returns U

foldRight

  • foldRight<U>(zero: U, fn: function): U
  • Reduces the collection to a single value. Right-associative.

    Example:

    Vector.of("a", "b", "c").foldRight("!", (x,xs) => xs+x)
    => "!cba"
    

    Type parameters

    • U

    Parameters

    • zero: U

      The initial value

    • fn: function

      A function taking the current collection item and the previous value , and returning an updated value.

        • (cur: T, soFar: U): U
        • Parameters

          • cur: T
          • soFar: U

          Returns U

    Returns U

forEach

  • forEach(fun: function): ISet<T>
  • Call a function for element in the collection.

    Parameters

    • fun: function
        • (x: T): void
        • Parameters

          • x: T

          Returns void

    Returns ISet<T>

groupBy

hashCode

  • hashCode(): number
  • Get a number for that object. Two different values may get the same number, but one value must always get the same number. The formula can impact performance.

    Returns number

intersect

  • Returns a new Set containing the intersection of this set and the other Set passed as parameter (the elements which are common to both sets) also see ISet.diff

    Parameters

    Returns ISet<T>

isEmpty

  • isEmpty(): boolean

isSubsetOf

  • Returns whether this set is a subset of the set you give as parameter (will return true also if both sets are equal)

    Parameters

    Returns boolean

length

  • length(): number

map

  • map<U>(mapper: function): ISet<U>
  • Return a new collection where each element was transformed by the mapper function you give. The resulting set may be smaller than the source.

    Type parameters

    • U

    Parameters

    Returns ISet<U>

mapOption

  • mapOption<U>(mapper: function): ISet<U>
  • Apply the mapper function on every element of this collection. The mapper function returns an Option; if the Option is a Some, the value it contains is added to the result Collection, if it's a None, the value is discarded.

    Type parameters

    • U

    Parameters

    Returns ISet<U>

maxBy

  • maxBy(compare: function): Option<T>

maxOn

  • Call the function you give for each value in the collection and return the element for which the result was the largest. Returns Option.none if the collection is empty.

    Vector.of({name:"Joe", age:12}, {name:"Paula", age:6}).maxOn(x=>x.age)
    => Option.of({name:"Joe", age:12})
    

    also see Collection.maxBy

    Parameters

    Returns Option<T>

minBy

  • minBy(compare: function): Option<T>

minOn

  • Call the function you give for each value in the collection and return the element for which the result was the smallest. Returns Option.none if the collection is empty.

    Vector.of({name:"Joe", age:12}, {name:"Paula", age:6}).minOn(x=>x.age)
    => Option.of({name:"Paula", age:6})
    

    also see Collection.minBy

    Parameters

    Returns Option<T>

partition

  • Returns a pair of two collections; the first one will only contain the items from this collection for which the predicate you give returns true, the second will only contain the items from this collection where the predicate returns false.

    Vector.of(1,2,3,4).partition(x => x%2===0)
    => [Vector.of(2,4), Vector.of(1,3)]
    

    Type parameters

    • U: T

    Parameters

    • predicate: function
        • (v: T): boolean
        • Parameters

          • v: T

          Returns boolean

    Returns [Collection<U>, Collection<Exclude<T, U>>]

  • Parameters

    • predicate: function
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns [Collection<T>, Collection<T>]

reduce

  • reduce(combine: function): Option<T>
  • Reduces the collection to a single value by repeatedly calling the combine function. No starting value. The order in which the elements are passed to the combining function is undetermined.

    Parameters

    • combine: function
        • (v1: T, v2: T): T
        • Parameters

          • v1: T
          • v2: T

          Returns T

    Returns Option<T>

removeAll

  • Returns a new set with all the elements of the current Set, minus the elements of the iterable you give as a parameter. If you call this function with a HashSet as parameter, rather call 'diff', as it'll be faster.

    Parameters

    Returns ISet<T>

single

sumOn

  • sumOn(getNumber: function): number
  • Call the function you give for each element in the collection and sum all the numbers, return that sum. Will return 0 if the collection is empty.

    Vector.of(1,2,3).sumOn(x=>x)
    => 6
    

    Parameters

    • getNumber: function
        • (v: T): number
        • Parameters

          • v: T

          Returns number

    Returns number

toArray

  • Converts this set to an array. Since a Set is not ordered and since this method returns a JS array, it can be awkward to get an array sorted in the way you'd like. So you can pass an optional sorting function too.

    HashSet.of(1,2,3).toArray().sort()
    => [1,2,3]
    
    HashSet.of(1,2,3).toArray({sortOn:x=>x})
    => [1,2,3]
    
    HashSet.of(1,2,3).toArray({sortBy:(x,y)=>x-y})
    => [1,2,3]
    

    You can also pass an array in sortOn, listing lambdas to several fields to sort by those fields, and also {desc:lambda} to sort by some fields descending.

    Parameters

    Returns Array<T & WithEquality>

toJsSet

  • toJsSet(keyConvert: function): Set<string>
  • toJsSet(keyConvert: function): Set<number>
  • toJsSet(keyConvert: function): Set<boolean>

toLinkedList

toString

  • toString(): string
  • Get a human-friendly string representation of that value.

    Returns string

toVector

transform

  • transform<U>(converter: function): U
  • Transform this value to another value type. Enables fluent-style programming by chaining calls.

    Type parameters

    • U

    Parameters

    • converter: function
        • Parameters

          Returns U

    Returns U

Generated using TypeDoc