Comments (1)
Just for posterity: I Cannot answer for the original authors, but most likely it's because the desired equality is actually element equality.
The typles are used as simple value types, and it would probably be surprising if you did:
var pair = Tuple2(1, 2);
Set<Tuple2<num, num>> set = {pair};
print(set.contains(Tuple2(1, 2)));
and it printed false
. Which it would, becasue var pair = Tuple2(1, 2);
has no context type, so it infers Tuple2<int, int>
, which contains(Tuple2(1, 2))
has a context type of Tuple<num, num>
and would therefore create an instance of that.
Tuples are immutable, so the optimal runtime type would be type arguments that were the runtime type of the elements. A Tuple2<num, num>(1, 2)
is strictly less useful than a Tuple2<int, int>(1, 2)
, because the latter can be assigned to Tuple2<num, num>
and then works fine at that type, but the former cannot be used as a Tuple2<int, int>
at all.
(And that's what Dart 3.0's records do: Their runtime type is the record type of their fields' objects runtime type.)
So the class will allow you to give every tuple its optimal type arguments, but not punish you if it fails (not until you try a cast which won't work).
Using only the values for equality is allowing precisely that
Secondarily, if the type parameters were part of equality, they should probably also be part of hashCode
, which means taking the hash code of reified Type
objects.
It'd not be wrong to not include the types in the hash code, after all it's not incorrect for non-equal values to have the same hash code, but it would risk hash code conflicts, if a Tuple2<int, int>(1, 2)
and Tuple2<num, num>(1, 2)
ended up in the same hash set/map.
from tuple.dart.
Related Issues (16)
- Add include to example on github and package
- Add .cast() methods HOT 1
- Common interface HOT 5
- publish the latest contents HOT 4
- Please add tuple2 to map HOT 1
- Compatibility with json_serializable HOT 2
- [Proposal] Indexing tuples HOT 4
- Stable null safety release
- Set max SDK version to `<3.0.0`? HOT 3
- Loop structure - Helper method HOT 1
- Should this package be deprecated/unlisted? HOT 2
- update on package:tuple status
- Undefined class 'Tuple2'. Try changing the name to the name of an existing class, or creating a class with the name 'Tuple2
- first/second/third/last? HOT 1
- Whats the point of Tuple always being 'const'? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tuple.dart.