The type of the first value.
The type of the second value.
Constructor of Pair.
FirstType element.
SecondType element.
Returns the first value of this first/second pair.
The first value of this first/second pair.
Returns the second value of this first/second pair.
The second value of this first/second pair.
Class Pair implements KoconutEquatable. The 'equalsTo' method of this basically check whether each individual element (first/second) is same or not. When the type of each element is child of KoconutEquatable, it'd be done by using its 'equalsTo' method. Otherwise, it'd be done simply by '==' operator.
// Case 1 -- All values are simply number or string
const myPairCase1_01 = Pair.from([10, 20])
const myPairCase1_02 = Pair.from([10, 20])
console.log(`${myPairCase1_01.equalsTo(myPairCase1_02)}`)
// ↑ true
const myPairCase1_03 = Pair.from(["Apex", "Captain"])
const myPairCase1_04 = Pair.from(["Apex", "Captain"])
console.log(`${myPairCase1_03 == myPairCase1_04}`)
// ↑ false
console.log(`${myPairCase1_03.equalsTo(myPairCase1_04)}`)
// ↑ true
// Case 2 -- First Type is indistinguishable class
class MyClass {
private value : string
constructor(value : string) {
this.value = value
}
}
const myPairCase2_01 = Pair.from([new MyClass("Apex"), "Captain"])
const myPairCase2_02 = Pair.from([new MyClass("Apex"), "Captain"])
console.log(`${myPairCase2_01.equalsTo(myPairCase2_02)}`)
// ↑ false
// Case 3 -- First Type is distinguishable class
class MyDistinguishableClass implements KoconutEquatable {
private value : string
constructor(value : string) {
this.value = value
}
equalsTo(other : MyDistinguishableClass) : boolean {
return this.value == other.value
}
}
const myPairCase3_01 = Pair.from([new MyDistinguishableClass("Apex"), "Captain"])
const myPairCase3_02 = Pair.from([new MyDistinguishableClass("Apex"), "Captain"])
console.log(`${myPairCase3_01.equalsTo(myPairCase3_02)}`)
// ↑ true
Turns this Pair instance into a simple array.
const myPair = Pair.from(["Apex","Captain"])
console.log(myPair.toArray())
// ↑ [ 'Apex', 'Captain' ]
Turns this Pair instance into a simple JSON object string.
const myPair = Pair.from(["Apex","Captain"])
console.log(myPair.toString()) // Or, you can use console.log(`${myPair}`)
// ↑ {"first":"Apex","second":"Captain"}
Static
fromCreate a Pair instance by iterable two values pair.
const myPair = Pair.from(["Apex","Captain"])
console.log(myPair)
// ↑ Pair { firstElement: 'Apex', secondElement: 'Captain' }
Values pair of first/second as iterable.
Generated using TypeDoc
Represents a generic pair of two Values. There is no meaning attached to values in this class. It can be used for any purpose. Pair exhibits values semantics, i.e. two pairs are equal if both components are equal. However, if any of those two values are instance of class, you'd better make the class explicitly distinguishable by inheriting KoconutEquatable. Please, check the example of 'equalsTo' method
See