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