Class Entry<KeyType, ValueType>

Represents a key/value pair for KoconutMap. The type of key basically could be any kind of class instance, however 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](KoconutEntry.html), [Pair](Pair.html), [KoconutPair](KoconutPair.html)

-- Container --
[KoconutMap](KoconutMap.html)

-- Protocol --
[KoconutEquatable](../interfaces/KoconutEquatable.html)

Type Parameters

  • KeyType

    The type of the key value.

  • ValueType

    The type of the value.

Hierarchy

  • Entry

Implements

Constructors

Accessors

Methods

Constructors

  • new Entry<KeyType, ValueType>(keyElement: KeyType, valueElement: ValueType): Entry<KeyType, ValueType>
  • Constructor of Entry.

    Type Parameters

    • KeyType

    • ValueType

    Parameters

    • keyElement: KeyType

      KeyType element it'd better be distinguishable.

    • valueElement: ValueType

      ValueType element.

    Returns Entry<KeyType, ValueType>

Accessors

Methods

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

    Returns

    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

  • Turns this Entry instance into a simple array.

    Returns

    Example

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

    Returns [KeyType, ValueType]

  • Turns this Entry instance into a simple Pair

    Returns

    Example

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

    Returns Pair<KeyType, ValueType>

  • Turns this Entry into a simple JSON object string.

    Returns

    Example

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

    Returns string

  • Create an Entry instance by iterable two values pair.

    Returns

    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