diff --git a/packages/wyatt_type_utils/lib/src/pair/pair.dart b/packages/wyatt_type_utils/lib/src/pair/pair.dart new file mode 100644 index 00000000..e32b94bb --- /dev/null +++ b/packages/wyatt_type_utils/lib/src/pair/pair.dart @@ -0,0 +1,56 @@ +// 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 . + +extension PairExtension on Pair { + List toList() => List.from([left, right]); +} + +/// {@template pair} +/// [Pair] is a simple object which contains pair of two values. +/// {@endtemplate} +class Pair { + final L? left; + final R? right; + + /// {@macro pair} + const Pair(this.left, this.right); + + @override + String toString() => '($left, $right)'; + + Pair copyWith({ + L? left, + R? right, + }) => + Pair( + left ?? this.left, + right ?? this.right, + ); + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(covariant Pair 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; +}