Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IMap<K, V>

A generic interface for a dictionary, mapping keys to values.

Type parameters

  • K

    the key type

  • V

    the value type

Hierarchy

Implemented by

Index

Methods

__@iterator

  • __@iterator(): Iterator<[K, V]>
  • Returns Iterator<[K, V]>

__computed

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

    Returns string

allMatch

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

    Parameters

    • predicate: function
        • (k: K, v: V): boolean
        • Parameters

          • k: K
          • v: V

          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
        • (k: K, v: V): boolean
        • Parameters

          • k: K
          • v: V

          Returns boolean

    Returns boolean

contains

containsKey

  • Returns true if there is item with that key in the collection, false otherwise.

    Parameters

    Returns boolean

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

  • filter(predicate: function): IMap<K, V>
  • Call a predicate for each element in the collection, build a new collection holding only the elements for which the predicate returned true.

    Parameters

    • predicate: function
        • (k: K, v: V): boolean
        • Parameters

          • k: K
          • v: V

          Returns boolean

    Returns IMap<K, V>

filterKeys

  • filterKeys<U>(fn: function): IMap<U, V>
  • filterKeys(predicate: function): IMap<K, V>
  • Call a predicate for each key in the collection, build a new collection holding only the elements for which the predicate returned true.

    Type parameters

    • U: K

    Parameters

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

          • v: K

          Returns boolean

    Returns IMap<U, V>

  • Parameters

    • predicate: function
        • (k: K): boolean
        • Parameters

          • k: K

          Returns boolean

    Returns IMap<K, V>

filterValues

  • filterValues<U>(fn: function): IMap<K, U>
  • filterValues(predicate: function): IMap<K, V>
  • Call a predicate for each value in the collection, build a new collection holding only the elements for which the predicate returned true.

    Type parameters

    • U: V

    Parameters

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

          • v: V

          Returns boolean

    Returns IMap<K, U>

  • Parameters

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

          • v: V

          Returns boolean

    Returns IMap<K, V>

flatMap

  • flatMap<K2, V2>(fn: function): IMap<K2, V2>
  • Calls the function you give for each item in the map, your function returns a map, all the maps are merged.

    Type parameters

    • K2

    • V2

    Parameters

    • fn: function

    Returns IMap<K2, V2>

fold

  • fold(zero: [K, V], fn: function): [K, V]
  • 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: [K, V]
    • fn: function
        • (v1: [K, V], v2: [K, V]): [K, V]
        • Parameters

          • v1: [K, V]
          • v2: [K, V]

          Returns [K, V]

    Returns [K, V]

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: [K, V]): U
        • Parameters

          • soFar: U
          • cur: [K, V]

          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: [K, V], soFar: U): U
        • Parameters

          • cur: [K, V]
          • soFar: U

          Returns U

    Returns U

forEach

  • forEach(fun: function): IMap<K, V>
  • Call a function for element in the collection.

    Parameters

    • fun: function
        • (x: [K, V]): void
        • Parameters

          • x: [K, V]

          Returns void

    Returns IMap<K, V>

get

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

isEmpty

  • isEmpty(): boolean
  • true if the map is empty, false otherwise.

    Returns boolean

keySet

  • Get a Set containing all the keys in the map

    Returns ISet<K>

length

  • length(): number
  • number of items in the map

    Returns number

map

  • map<K2, V2>(fn: function): IMap<K2, V2>
  • Return a new map where each entry was transformed by the mapper function you give. You return key,value as pairs.

    Type parameters

    • K2

    • V2

    Parameters

    Returns IMap<K2, V2>

mapValues

  • mapValues<V2>(fn: function): IMap<K, V2>
  • Return a new map where keys are the same as in this one, but values are transformed by the mapper function you give. You return key,value as pairs.

    Type parameters

    • V2

    Parameters

    • fn: function
        • (v: V): V2
        • Parameters

          • v: V

          Returns V2

    Returns IMap<K, V2>

mergeWith

  • mergeWith(other: Iterable<[K & WithEquality, V]>, merge: function): IMap<K, V>
  • Create a new map combining the entries of this map, and the other map you give. In case an entry from this map and the other map have the same key, the merge function will be invoked to get a combined value.

    Parameters

    • other: Iterable<[K & WithEquality, V]>

      another map to merge with this one

    • merge: function

      a merge function to combine two values in case two entries share the same key.

        • (v1: V, v2: V): V
        • Parameters

          • v1: V
          • v2: V

          Returns V

    Returns IMap<K, V>

put

  • Add a new entry in the map. If there was entry with the same key, it will be overwritten.

    Parameters

    Returns IMap<K, V>

putWithMerge

  • Add a new entry in the map; in case there was already an entry with the same key, the merge function will be invoked with the old and the new value to produce the value to take into account.

    Parameters

    • k: K & WithEquality

      the key

    • v: V

      the value

    • merge: function

      a function to merge old and new values in case of conflict.

        • (v1: V, v2: V): V
        • Parameters

          • v1: V
          • v2: V

          Returns V

    Returns IMap<K, V>

reduce

  • reduce(combine: function): Option<[K, V]>
  • 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: [K, V], v2: [K, V]): [K, V]
        • Parameters

          • v1: [K, V]
          • v2: [K, V]

          Returns [K, V]

    Returns Option<[K, V]>

remove

toArray

  • toArray(): Array<[K, V]>
  • Convert to array.

    Returns Array<[K, V]>

toJsMap

  • toJsMap(keyConvert: function): Map<string, V>
  • toJsMap(keyConvert: function): Map<number, V>
  • toJsMap(keyConvert: function): Map<boolean, V>

toLinkedList

  • Convert this map to a List of key,value pairs. Note that Map is already an iterable of key,value pairs!

    Returns LinkedList<[K, V]>

toObjectDictionary

  • toObjectDictionary(keyConvert: function): object
  • Convert to a javascript object dictionary You must provide a function to convert the key to a string.

    HashMap.of<string,number>(["a",1],["b",2])
        .toObjectDictionary(x=>x);
    => {a:1,b:2}
    

    Parameters

    • keyConvert: function
        • (k: K): string
        • Parameters

          • k: K

          Returns string

    Returns object

    • [index: string]: V

toString

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

    Returns string

toVector

  • Convert this map to a vector of key,value pairs. Note that Map is already an iterable of key,value pairs!

    Returns Vector<[K, V]>

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
        • (x: IMap<K, V>): U
        • Parameters

          Returns U

    Returns U

valueIterable

  • valueIterable(): Iterable<V>
  • Get an iterable containing all the values in the map (can't return a set as we don't constrain map values to have equality in the generics type)

    Returns Iterable<V>

Generated using TypeDoc