//================================================================ /** * @packageDocumentation * @module std */ //================================================================ import { IPair } from "./IPair"; import { IComparable } from "../functional/IComparable"; import { hash } from "../functional/hash"; import { less, equal_to } from "../functional/comparators"; /** * Pair of two elements. * * @author Jeongho Nam - https://github.com/samchon */ export class Pair implements IPair, IComparable> { /** * @inheritDoc */ public first: First; /** * @inheritDoc */ public second: Second; /* --------------------------------------------------------- CONSTRUCTORS --------------------------------------------------------- */ /** * Initializer Constructor. * * @param first The first element. * @param second The second element. */ public constructor(first: First, second: Second) { this.first = first; this.second = second; } /* --------------------------------------------------------- COMPARISON --------------------------------------------------------- */ /** * @inheritDoc */ public equals( pair: Pair, ): boolean { return ( equal_to(this.first, pair.first) && equal_to(this.second, pair.second) ); } /** * @inheritDoc */ public less( pair: Pair, ): boolean { if (equal_to(this.first, pair.first) === false) return less(this.first, pair.first); else return less(this.second, pair.second); } /** * @inheritDoc */ public hashCode(): number { return hash(this.first, this.second); } } /** * Create a {@link Pair}. * * @param first The 1st element. * @param second The 2nd element. * * @return A {@link Pair} object. */ export function make_pair( first: First, second: Second, ): Pair { return new Pair(first, second); }