// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

extension PairExtension<T> on Pair<T, T> {
  List<T?> toList() => List.from([left, right]);
}

/// {@template pair}
/// [Pair] is a simple object which contains pair of two values.
/// {@endtemplate}
class Pair<L, R> {

  /// {@macro pair}
  const Pair(this.left, this.right);
  final L? left;
  final R? right;

  @override
  String toString() => '($left, $right)';

  Pair<L, R> copyWith({
    L? left,
    R? right,
  }) =>
      Pair<L, R>(
        left ?? this.left,
        right ?? this.right,
      );

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  bool operator ==(covariant Pair<L, R> other) {
    if (identical(this, other)) {
      return true;
    }

    return other.left == left && other.right == right;
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  int get hashCode => left.hashCode ^ right.hashCode;
}
