google / tuple.dart

A library providing a tuple data structure
https://pub.dev/packages/tuple
BSD 2-Clause "Simplified" License
195 stars 26 forks source link

[Proposal] Indexing tuples #23

Closed KristianBalaj closed 3 years ago

KristianBalaj commented 4 years ago

Hey nice work with the tuples 👋

I would like to propose a feature, to make the tuples indexable.

Example:

final a = Tuple2(1, 2);
print(a[0].toString());
print(a[1].toString());

This code prints '1' and '2'.

You could assign me and I would do the PR.

KristianBalaj commented 4 years ago

Of course the indexing would be just for getting the values. (since the tuples are written in immutable fashion)

M123-dev commented 4 years ago
const t = const Tuple2<String, int>('a', 10);

print(t.item1); // prints 'a'
print(t.item2); // prints '10'

Isn't this snippet from the README.md what you meant only in a different form? Maybe this is already because of your issue if so you can close this issue 😄

znjameswu commented 3 years ago

What would be the return type of operator [] for Tuple2<int, String>? It's hard to reason.

KristianBalaj commented 3 years ago

@znjameswu yeah, you're right. That's a real problem. We don't want dynamic return, I should close the issue then.