Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HashSet<T>

An unordered collection of values, where no two values may be equal. A value can only be present once.

Type parameters

  • T

    the item type

Hierarchy

  • HashSet

Implements

Index

Methods

Static empty

Static isEmpty

  • isEmpty<T>(v: HashSet<T>): boolean
  • Curried predicate to find out whether the HashSet is empty.

    Vector.of(HashSet.of(1), HashSet.empty<number>())
        .filter(HashSet.isEmpty)
    => Vector.of(HashSet.empty<number>())
    

    Type parameters

    • T

    Parameters

    Returns boolean

Static isNotEmpty

  • isNotEmpty<T>(v: HashSet<T>): boolean
  • Curried predicate to find out whether the HashSet is empty.

    Vector.of(HashSet.of(1), HashSet.empty<number>())
        .filter(HashSet.isNotEmpty)
    => Vector.of(HashSet.of(1))
    

    Type parameters

    • T

    Parameters

    Returns boolean

Static of

  • Build a hashset from a series of items (any number, as parameters)

    Type parameters

    • T

      the item type

    Parameters

    Returns HashSet<T>

Static ofIterable

  • Build a hashset from any iterable, which means also an array for instance.

    Type parameters

    • T

      the item type

    Parameters

    Returns HashSet<T>

__@iterator

  • __@iterator(): Iterator<T>

__computed

  • __computed(): 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

  • equals(other: HashSet<T>): boolean
  • 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

  • filter<U>(fn: function): HashSet<U>
  • filter(predicate: function): HashSet<T>
  • 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 HashSet<U>

  • Parameters

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

          • v: T

          Returns boolean

    Returns HashSet<T>

findAny

  • findAny(predicate: function): Option<T>
  • Search for an item matching the predicate you pass, return Option.Some of that element if found, Option.None otherwise. We name the method findAny instead of find to emphasize that there is not ordering in a hashset.

    HashSet.of(1,2,3).findAny(x => x>=3)
    => Option.of(3)
    
    HashSet.of(1,2,3).findAny(x => x>=4)
    => Option.none<number>()
    

    Parameters

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

          • v: T

          Returns boolean

    Returns Option<T>

flatMap

  • flatMap<U>(mapper: function): HashSet<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. No guarantees for the order of items in a hashset!

    Example:

    HashSet.of("a", "bb", "ccc").foldLeft(0, (soFar,item) => soFar+item.length);
    => 6
    

    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. No guarantees for the order of items in a hashset!

    Example:

    HashSet.of("a", "bb", "ccc").foldRight(0, (item,soFar) => soFar+item.length);
    => 6
    

    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): HashSet<T>
  • Call a function for element in the collection.

    Parameters

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

          • x: T

          Returns void

    Returns HashSet<T>

groupBy

  • Group elements in the collection using a classifier function. Elements are then organized in a map. The key is the value of the classifier, and in value we get the list of elements matching that value.

    also see HashSet.arrangeBy

    Type parameters

    • C

    Parameters

    Returns HashMap<C, HashSet<T>>

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

isEmpty

  • isEmpty(): boolean

isSubsetOf

length

  • length(): number

map

  • map<U>(mapper: function): HashSet<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 HashSet<U>

mapOption

  • mapOption<U>(mapper: function): HashSet<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.

    HashSet.of(1,2,6).mapOption(x => x%2===0 ?
        Option.of(x+1) : Option.none<number>())
    => HashSet.of(3, 7)
    

    Type parameters

    • U

    Parameters

    Returns HashSet<U>

maxBy

  • maxBy(compare: function): Option<T>
  • Compare values in the collection and return the largest element. Returns Option.none if the collection is empty.

    also see HashSet.maxOn

    Parameters

    • compare: function

    Returns 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.

    also see HashSet.maxBy

    Parameters

    Returns Option<T>

minBy

  • minBy(compare: function): Option<T>
  • Compare values in the collection and return the smallest element. Returns Option.none if the collection is empty.

    also see HashSet.minOn

    Parameters

    • compare: function

    Returns 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.

    also see HashSet.minBy

    Parameters

    Returns Option<T>

mkString

  • mkString(separator: string): string
  • Joins elements of the collection by a separator. Example:

    HashSet.of(1,2,3).mkString(", ")
    => "1, 2, 3"
    

    (of course, order is not guaranteed)

    Parameters

    • separator: string

    Returns string

partition

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

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

    Type parameters

    • U: T

    Parameters

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

          • v: T

          Returns boolean

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

  • Parameters

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

          • x: T

          Returns boolean

    Returns [HashSet<T>, HashSet<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>

remove

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 HashSet<T>

single

  • If the collection contains a single element, return Some of its value, otherwise return None.

    Returns Option<T>

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.

    HashSet.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

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

    Returns U

Generated using TypeDoc