Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: lib/src/tuple.dart

Issue 2939773003: Initialize dart-lang/tuple with the tuple package at v1.0.1. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « README.md ('k') | lib/tuple.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the tuple project authors. Please see the AUTHORS
2 // file for details. All rights reserved. Use of this source code is governed
3 // by a BSD-style license that can be found in the LICENSE file.
4
5 part of tuple;
6
7 /// Represents a 2-tuple, or pair.
8 class Tuple2<T1, T2> {
9 /// Returns the first item of the tuple
10 final T1 item1;
11
12 /// Returns the second item of the tuple
13 final T2 item2;
14
15 /// Creates a new tuple value with the specified items.
16 const Tuple2(this.item1, this.item2);
17
18 /// Create a new tuple value with the specified list [items].
19 factory Tuple2.fromList(List items) {
20 if (items.length != 2) {
21 throw new ArgumentError('items must have length 2');
22 }
23
24 return new Tuple2<T1, T2>(items[0] as T1, items[1] as T2);
25 }
26
27 /// Returns a tuple with the first item set to the specified value.
28 Tuple2<T1, T2> withItem1(T1 v) {
29 return new Tuple2<T1, T2>(v, item2);
30 }
31
32 /// Returns a tuple with the second item set to the specified value.
33 Tuple2<T1, T2> withItem2(T2 v) {
34 return new Tuple2<T1, T2>(item1, v);
35 }
36
37 /// Creates a [List] containing the items of this [Tuple2].
38 ///
39 /// The elements are in item order. The list is variable-length
40 /// if [growable] is true.
41 List toList({bool growable: false}) =>
42 new List.from([item1, item2], growable: growable);
43
44 @override
45 String toString() => '[$item1, $item2]';
46
47 @override
48 bool operator ==(o) => o is Tuple2 && o.item1 == item1 && o.item2 == item2;
49
50 @override
51 int get hashCode => hash2(item1.hashCode, item2.hashCode);
52 }
53
54 /// Represents a 3-tuple, or triple.
55 class Tuple3<T1, T2, T3> {
56 /// Returns the first item of the tuple
57 final T1 item1;
58
59 /// Returns the second item of the tuple
60 final T2 item2;
61
62 /// Returns the third item of the tuple
63 final T3 item3;
64
65 /// Creates a new tuple value with the specified items.
66 const Tuple3(this.item1, this.item2, this.item3);
67
68 /// Create a new tuple value with the specified list [items].
69 factory Tuple3.fromList(List items) {
70 if (items.length != 3) {
71 throw new ArgumentError('items must have length 3');
72 }
73
74 return new Tuple3<T1, T2, T3>(
75 items[0] as T1, items[1] as T2, items[2] as T3);
76 }
77
78 /// Returns a tuple with the first item set to the specified value.
79 Tuple3<T1, T2, T3> withItem1(T1 v) {
80 return new Tuple3<T1, T2, T3>(v, item2, item3);
81 }
82
83 /// Returns a tuple with the second item set to the specified value.
84 Tuple3<T1, T2, T3> withItem2(T2 v) {
85 return new Tuple3<T1, T2, T3>(item1, v, item3);
86 }
87
88 /// Returns a tuple with the third item set to the specified value.
89 Tuple3<T1, T2, T3> withItem3(T3 v) {
90 return new Tuple3<T1, T2, T3>(item1, item2, v);
91 }
92
93 /// Creates a [List] containing the items of this [Tuple3].
94 ///
95 /// The elements are in item order. The list is variable-length
96 /// if [growable] is true.
97 List toList({bool growable: false}) =>
98 new List.from([item1, item2, item3], growable: growable);
99
100 @override
101 String toString() => '[$item1, $item2, $item3]';
102
103 @override
104 bool operator ==(o) =>
105 o is Tuple3 && o.item1 == item1 && o.item2 == item2 && o.item3 == item3;
106
107 @override
108 int get hashCode => hash3(item1.hashCode, item2.hashCode, item3.hashCode);
109 }
110
111 /// Represents a 4-tuple, or quadruple.
112 class Tuple4<T1, T2, T3, T4> {
113 /// Returns the first item of the tuple
114 final T1 item1;
115
116 /// Returns the second item of the tuple
117 final T2 item2;
118
119 /// Returns the third item of the tuple
120 final T3 item3;
121
122 /// Returns the fourth item of the tuple
123 final T4 item4;
124
125 /// Creates a new tuple value with the specified items.
126 const Tuple4(this.item1, this.item2, this.item3, this.item4);
127
128 /// Create a new tuple value with the specified list [items].
129 factory Tuple4.fromList(List items) {
130 if (items.length != 4) {
131 throw new ArgumentError('items must have length 4');
132 }
133
134 return new Tuple4<T1, T2, T3, T4>(
135 items[0] as T1, items[1] as T2, items[2] as T3, items[3] as T4);
136 }
137
138 /// Returns a tuple with the first item set to the specified value.
139 Tuple4<T1, T2, T3, T4> withItem1(T1 v) {
140 return new Tuple4<T1, T2, T3, T4>(v, item2, item3, item4);
141 }
142
143 /// Returns a tuple with the second item set to the specified value.
144 Tuple4<T1, T2, T3, T4> withItem2(T2 v) {
145 return new Tuple4<T1, T2, T3, T4>(item1, v, item3, item4);
146 }
147
148 /// Returns a tuple with the third item set to the specified value.
149 Tuple4<T1, T2, T3, T4> withItem3(T3 v) {
150 return new Tuple4<T1, T2, T3, T4>(item1, item2, v, item4);
151 }
152
153 /// Returns a tuple with the fourth item set to the specified value.
154 Tuple4<T1, T2, T3, T4> withItem4(T4 v) {
155 return new Tuple4<T1, T2, T3, T4>(item1, item2, item3, v);
156 }
157
158 /// Creates a [List] containing the items of this [Tuple4].
159 ///
160 /// The elements are in item order. The list is variable-length
161 /// if [growable] is true.
162 List toList({bool growable: false}) =>
163 new List.from([item1, item2, item3, item4], growable: growable);
164
165 @override
166 String toString() => '[$item1, $item2, $item3, $item4]';
167
168 @override
169 bool operator ==(o) => o is Tuple4 &&
170 o.item1 == item1 &&
171 o.item2 == item2 &&
172 o.item3 == item3 &&
173 o.item4 == item4;
174
175 @override
176 int get hashCode =>
177 hash4(item1.hashCode, item2.hashCode, item3.hashCode, item4.hashCode);
178 }
179
180 /// Represents a 5-tuple, or quintuple.
181 class Tuple5<T1, T2, T3, T4, T5> {
182 /// Returns the first item of the tuple
183 final T1 item1;
184
185 /// Returns the second item of the tuple
186 final T2 item2;
187
188 /// Returns the third item of the tuple
189 final T3 item3;
190
191 /// Returns the fourth item of the tuple
192 final T4 item4;
193
194 /// Returns the fifth item of the tuple
195 final T5 item5;
196
197 /// Creates a new tuple value with the specified items.
198 const Tuple5(this.item1, this.item2, this.item3, this.item4, this.item5);
199
200 /// Create a new tuple value with the specified list [items].
201 factory Tuple5.fromList(List items) {
202 if (items.length != 5) {
203 throw new ArgumentError('items must have length 5');
204 }
205
206 return new Tuple5<T1, T2, T3, T4, T5>(items[0] as T1, items[1] as T2,
207 items[2] as T3, items[3] as T4, items[4] as T5);
208 }
209
210 /// Returns a tuple with the first item set to the specified value.
211 Tuple5<T1, T2, T3, T4, T5> withItem1(T1 v) {
212 return new Tuple5<T1, T2, T3, T4, T5>(v, item2, item3, item4, item5);
213 }
214
215 /// Returns a tuple with the second item set to the specified value.
216 Tuple5<T1, T2, T3, T4, T5> withItem2(T2 v) {
217 return new Tuple5<T1, T2, T3, T4, T5>(item1, v, item3, item4, item5);
218 }
219
220 /// Returns a tuple with the third item set to the specified value.
221 Tuple5<T1, T2, T3, T4, T5> withItem3(T3 v) {
222 return new Tuple5<T1, T2, T3, T4, T5>(item1, item2, v, item4, item5);
223 }
224
225 /// Returns a tuple with the fourth item set to the specified value.
226 Tuple5<T1, T2, T3, T4, T5> withItem4(T4 v) {
227 return new Tuple5<T1, T2, T3, T4, T5>(item1, item2, item3, v, item5);
228 }
229
230 /// Returns a tuple with the fifth item set to the specified value.
231 Tuple5<T1, T2, T3, T4, T5> withItem5(T5 v) {
232 return new Tuple5<T1, T2, T3, T4, T5>(item1, item2, item3, item4, v);
233 }
234
235 /// Creates a [List] containing the items of this [Tuple5].
236 ///
237 /// The elements are in item order. The list is variable-length
238 /// if [growable] is true.
239 List toList({bool growable: false}) =>
240 new List.from([item1, item2, item3, item4, item5], growable: growable);
241
242 @override
243 String toString() => '[$item1, $item2, $item3, $item4, $item5]';
244
245 @override
246 bool operator ==(o) => o is Tuple5 &&
247 o.item1 == item1 &&
248 o.item2 == item2 &&
249 o.item3 == item3 &&
250 o.item4 == item4 &&
251 o.item5 == item5;
252
253 @override
254 int get hashCode => hashObjects([
255 item1.hashCode,
256 item2.hashCode,
257 item3.hashCode,
258 item4.hashCode,
259 item5.hashCode
260 ]);
261 }
262
263 /// Represents a 6-tuple, or sextuple.
264 class Tuple6<T1, T2, T3, T4, T5, T6> {
265 /// Returns the first item of the tuple
266 final T1 item1;
267
268 /// Returns the second item of the tuple
269 final T2 item2;
270
271 /// Returns the third item of the tuple
272 final T3 item3;
273
274 /// Returns the fourth item of the tuple
275 final T4 item4;
276
277 /// Returns the fifth item of the tuple
278 final T5 item5;
279
280 /// Returns the sixth item of the tuple
281 final T6 item6;
282
283 /// Creates a new tuple value with the specified items.
284 const Tuple6(
285 this.item1, this.item2, this.item3, this.item4, this.item5, this.item6);
286
287 /// Create a new tuple value with the specified list [items].
288 factory Tuple6.fromList(List items) {
289 if (items.length != 6) {
290 throw new ArgumentError('items must have length 6');
291 }
292
293 return new Tuple6<T1, T2, T3, T4, T5, T6>(items[0] as T1, items[1] as T2,
294 items[2] as T3, items[3] as T4, items[4] as T5, items[5] as T6);
295 }
296
297 /// Returns a tuple with the first item set to the specified value.
298 Tuple6<T1, T2, T3, T4, T5, T6> withItem1(T1 v) {
299 return new Tuple6<T1, T2, T3, T4, T5, T6>(
300 v, item2, item3, item4, item5, item6);
301 }
302
303 /// Returns a tuple with the second item set to the specified value.
304 Tuple6<T1, T2, T3, T4, T5, T6> withItem2(T2 v) {
305 return new Tuple6<T1, T2, T3, T4, T5, T6>(
306 item1, v, item3, item4, item5, item6);
307 }
308
309 /// Returns a tuple with the third item set to the specified value.
310 Tuple6<T1, T2, T3, T4, T5, T6> withItem3(T3 v) {
311 return new Tuple6<T1, T2, T3, T4, T5, T6>(
312 item1, item2, v, item4, item5, item6);
313 }
314
315 /// Returns a tuple with the fourth item set to the specified value.
316 Tuple6<T1, T2, T3, T4, T5, T6> withItem4(T4 v) {
317 return new Tuple6<T1, T2, T3, T4, T5, T6>(
318 item1, item2, item3, v, item5, item6);
319 }
320
321 /// Returns a tuple with the fifth item set to the specified value.
322 Tuple6<T1, T2, T3, T4, T5, T6> withItem5(T5 v) {
323 return new Tuple6<T1, T2, T3, T4, T5, T6>(
324 item1, item2, item3, item4, v, item6);
325 }
326
327 /// Returns a tuple with the sixth item set to the specified value.
328 Tuple6<T1, T2, T3, T4, T5, T6> withItem6(T6 v) {
329 return new Tuple6<T1, T2, T3, T4, T5, T6>(
330 item1, item2, item3, item4, item5, v);
331 }
332
333 /// Creates a [List] containing the items of this [Tuple5].
334 ///
335 /// The elements are in item order. The list is variable-length
336 /// if [growable] is true.
337 List toList({bool growable: false}) =>
338 new List.from([item1, item2, item3, item4, item5, item6],
339 growable: growable);
340
341 @override
342 String toString() => '[$item1, $item2, $item3, $item4, $item5, $item6]';
343
344 @override
345 bool operator ==(o) => o is Tuple6 &&
346 o.item1 == item1 &&
347 o.item2 == item2 &&
348 o.item3 == item3 &&
349 o.item4 == item4 &&
350 o.item5 == item5 &&
351 o.item6 == item6;
352
353 @override
354 int get hashCode => hashObjects([
355 item1.hashCode,
356 item2.hashCode,
357 item3.hashCode,
358 item4.hashCode,
359 item5.hashCode,
360 item6.hashCode
361 ]);
362 }
363
364 /// Represents a 7-tuple, or septuple.
365 class Tuple7<T1, T2, T3, T4, T5, T6, T7> {
366 /// Returns the first item of the tuple
367 final T1 item1;
368
369 /// Returns the second item of the tuple
370 final T2 item2;
371
372 /// Returns the third item of the tuple
373 final T3 item3;
374
375 /// Returns the fourth item of the tuple
376 final T4 item4;
377
378 /// Returns the fifth item of the tuple
379 final T5 item5;
380
381 /// Returns the sixth item of the tuple
382 final T6 item6;
383
384 /// Returns the seventh item of the tuple
385 final T7 item7;
386
387 /// Creates a new tuple value with the specified items.
388 const Tuple7(this.item1, this.item2, this.item3, this.item4, this.item5,
389 this.item6, this.item7);
390
391 /// Create a new tuple value with the specified list [items].
392 factory Tuple7.fromList(List items) {
393 if (items.length != 7) {
394 throw new ArgumentError('items must have length 7');
395 }
396
397 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
398 items[0] as T1,
399 items[1] as T2,
400 items[2] as T3,
401 items[3] as T4,
402 items[4] as T5,
403 items[5] as T6,
404 items[6] as T7);
405 }
406
407 /// Returns a tuple with the first item set to the specified value.
408 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem1(T1 v) {
409 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
410 v, item2, item3, item4, item5, item6, item7);
411 }
412
413 /// Returns a tuple with the second item set to the specified value.
414 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem2(T2 v) {
415 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
416 item1, v, item3, item4, item5, item6, item7);
417 }
418
419 /// Returns a tuple with the third item set to the specified value.
420 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem3(T3 v) {
421 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
422 item1, item2, v, item4, item5, item6, item7);
423 }
424
425 /// Returns a tuple with the fourth item set to the specified value.
426 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem4(T4 v) {
427 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
428 item1, item2, item3, v, item5, item6, item7);
429 }
430
431 /// Returns a tuple with the fifth item set to the specified value.
432 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem5(T5 v) {
433 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
434 item1, item2, item3, item4, v, item6, item7);
435 }
436
437 /// Returns a tuple with the sixth item set to the specified value.
438 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem6(T6 v) {
439 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
440 item1, item2, item3, item4, item5, v, item7);
441 }
442
443 /// Returns a tuple with the seventh item set to the specified value.
444 Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem7(T7 v) {
445 return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(
446 item1, item2, item3, item4, item5, item6, v);
447 }
448
449 /// Creates a [List] containing the items of this [Tuple5].
450 ///
451 /// The elements are in item order. The list is variable-length
452 /// if [growable] is true.
453 List toList({bool growable: false}) =>
454 new List.from([item1, item2, item3, item4, item5, item6, item7],
455 growable: growable);
456
457 @override
458 String toString() =>
459 '[$item1, $item2, $item3, $item4, $item5, $item6, $item7]';
460
461 @override
462 bool operator ==(o) => o is Tuple7 &&
463 o.item1 == item1 &&
464 o.item2 == item2 &&
465 o.item3 == item3 &&
466 o.item4 == item4 &&
467 o.item5 == item5 &&
468 o.item5 == item6 &&
469 o.item6 == item7;
470
471 @override
472 int get hashCode => hashObjects([
473 item1.hashCode,
474 item2.hashCode,
475 item3.hashCode,
476 item4.hashCode,
477 item5.hashCode,
478 item6.hashCode,
479 item7.hashCode
480 ]);
481 }
OLDNEW
« no previous file with comments | « README.md ('k') | lib/tuple.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698