|
| 1 | +// Copied from source at github.com/kseo/tuple/blob/470ed3aeb/lib/src/tuple.dart |
| 2 | + |
| 3 | +// Original copyright: |
| 4 | +// Copyright (c) 2014, the tuple project authors. Please see the AUTHORS |
| 5 | +// file for details. All rights reserved. Use of this source code is governed |
| 6 | +// by a BSD-style license that can be found in the LICENSE file. |
| 7 | + |
| 8 | +import 'package:quiver/core.dart'; |
| 9 | + |
| 10 | +/// Represents a 2-tuple, or pair. |
| 11 | +class Tuple2<T1, T2> { |
| 12 | + /// Returns the first item of the tuple |
| 13 | + final T1 item1; |
| 14 | + |
| 15 | + /// Returns the second item of the tuple |
| 16 | + final T2 item2; |
| 17 | + |
| 18 | + /// Creates a new tuple value with the specified items. |
| 19 | + const Tuple2(this.item1, this.item2); |
| 20 | + |
| 21 | + @override |
| 22 | + String toString() => '[$item1, $item2]'; |
| 23 | + |
| 24 | + @override |
| 25 | + bool operator ==(o) => o is Tuple2 && o.item1 == item1 && o.item2 == item2; |
| 26 | + |
| 27 | + @override |
| 28 | + int get hashCode => hash2(item1.hashCode, item2.hashCode); |
| 29 | +} |
| 30 | + |
| 31 | +/// Represents a 3-tuple, or triple. |
| 32 | +class Tuple3<T1, T2, T3> { |
| 33 | + /// Returns the first item of the tuple |
| 34 | + final T1 item1; |
| 35 | + |
| 36 | + /// Returns the second item of the tuple |
| 37 | + final T2 item2; |
| 38 | + |
| 39 | + /// Returns the third item of the tuple |
| 40 | + final T3 item3; |
| 41 | + |
| 42 | + /// Creates a new tuple value with the specified items. |
| 43 | + const Tuple3(this.item1, this.item2, this.item3); |
| 44 | + |
| 45 | + @override |
| 46 | + String toString() => '[$item1, $item2, $item3]'; |
| 47 | + |
| 48 | + @override |
| 49 | + bool operator ==(o) => |
| 50 | + o is Tuple3 && o.item1 == item1 && o.item2 == item2 && o.item3 == item3; |
| 51 | + |
| 52 | + @override |
| 53 | + int get hashCode => hash3(item1.hashCode, item2.hashCode, item3.hashCode); |
| 54 | +} |
| 55 | + |
| 56 | +/// Represents a 4-tuple, or quadruple. |
| 57 | +class Tuple4<T1, T2, T3, T4> { |
| 58 | + /// Returns the first item of the tuple |
| 59 | + final T1 item1; |
| 60 | + |
| 61 | + /// Returns the second item of the tuple |
| 62 | + final T2 item2; |
| 63 | + |
| 64 | + /// Returns the third item of the tuple |
| 65 | + final T3 item3; |
| 66 | + |
| 67 | + /// Returns the fourth item of the tuple |
| 68 | + final T4 item4; |
| 69 | + |
| 70 | + /// Creates a new tuple value with the specified items. |
| 71 | + const Tuple4(this.item1, this.item2, this.item3, this.item4); |
| 72 | + |
| 73 | + @override |
| 74 | + String toString() => '[$item1, $item2, $item3, $item4]'; |
| 75 | + |
| 76 | + @override |
| 77 | + bool operator ==(o) => |
| 78 | + o is Tuple4 && |
| 79 | + o.item1 == item1 && |
| 80 | + o.item2 == item2 && |
| 81 | + o.item3 == item3 && |
| 82 | + o.item4 == item4; |
| 83 | + |
| 84 | + @override |
| 85 | + int get hashCode => |
| 86 | + hash4(item1.hashCode, item2.hashCode, item3.hashCode, item4.hashCode); |
| 87 | +} |
0 commit comments