Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Entry<KeyType, ValueType>

Represents a key/value pair for KoconutMap. The type of key is basically could be any kind of class instance, but it is recommended to be a number, string or custom class that inherits KoconutEquatable. Otherwise, further equality check process in KoconutSet or KoconutMap will not work as intented. This is beacuse even if there are two different instances of same class, which have exactly identical properties, they are fundamentally indistinguishable from each other. Please, check the example of 'equalsTo' method

see
-- Base --
KoconutEntry, Pair, KoconutPair

-- Container --
KoconutMap

-- Protocol --
KoconutEquatable

Type parameters

  • KeyType

    The type of the key value.

  • ValueType

    The type of the value.

Hierarchy

  • Entry

Implements

Index

Constructors

Accessors

Methods

Constructors

constructor

  • new Entry(keyElement: KeyType, valueElement: ValueType): Entry

Accessors

key

  • get key(): KeyType

value

  • get value(): ValueType

Methods

equalsTo

  • Class Entry implements KoconutEquatable. The equality check process of this is done simply by using '==' operator when the KeyType is not KoconutEquatable, otherwise, by using the method 'equalsTo' to the the key element. Please, have a check following example.

    example
      class MyKey {
          private keyString : string
          constructor(keyString : string) {
              this.keyString = keyString
          }
      }
    
      class MyEquatableKey implements KoconutEquatable {
    
          private keyString : string
          constructor(keyString : string) {
              this.keyString = keyString
          }
          equalsTo(other : MyEquatableKey) {
              return this.keyString == other.keyString
          }
    
      }
    
      const myKeyEntry = Entry.from([new MyKey("myKeyString"), 0])
      const myKeyEntry2 = Entry.from([new MyKey("myKeyString"), 0])
      console.log(`${myKeyEntry.equalsTo(myKeyEntry2)}`)
      // ↑ false
    
      const myEquatableKeyEntry = Entry.from([new MyEquatableKey("myEquatableKeyString"), 0])
      const myEquatableKeyEntry2 = Entry.from([new MyEquatableKey("myEquatableKeyString"), 0])
      console.log(`${myEquatableKeyEntry.equalsTo(myEquatableKeyEntry2)}`)
      // ↑ true

    Parameters

    • other: Entry<KeyType, ValueType>

      Other Entry instance to check equality.

    Returns boolean | KoconutBoolean

toArray

  • toArray(): Array<KeyType | ValueType>
  • Turns this Entry instance into a simple array.

    example
    const myEntry = Entry.from(["Apex", "Captain"])
    console.log(myEntry.toArray())
    // ↑ [ 'Apex', 'Captain' ]

    Returns Array<KeyType | ValueType>

toPair

  • toPair(): Pair<KeyType, ValueType>
  • Turns this Entry instance into a simple Pair

    example
    const myEntry = Entry.from(["Apex", "Captain"])
    console.log(myEntry.toPair())
    // ↑ Pair { firstElement: 'Apex', secondElement: 'Captain' }

    Returns Pair<KeyType, ValueType>

toString

  • toString(): string
  • Turns this Entry into a simple JSON obeject string.

    example
    const myEntry = Entry.from(["Apex", "Captain"])
    console.log(myEntry.toString()) // Or, you can use console.log(`${myEntry}`)
    // ↑ {"keyElement":'Apex',"valueElement":"Captain"}

    Returns string

Static from

  • from<KeyType, ValueType>(entry: [KeyType, ValueType]): Entry<KeyType, ValueType>
  • Create an Entry instance by iterable two values pair.

    example
    const myEntry = Entry.from(["Apex", "Captain"])
    console.log(myEntry)
    // ↑ Entry { keyElement: 'Apex', valueElement: 'Captain' }

    Type parameters

    • KeyType

    • ValueType

    Parameters

    • entry: [KeyType, ValueType]

      Entry pair of key/value as iterable.

    Returns Entry<KeyType, ValueType>

Generated using TypeDoc