Git Product home page Git Product logo

tuple.dart's Introduction

Dart Pub package publisher

A library providing a tuple data structure.

Status - complete

We consider this package to be feature complete. With Dart 3.0, users now have the ability to use Records:

Records are an anonymous, immutable, aggregate type. Like other collection types, they let you bundle multiple objects into a single object.

  var record = (123, true);
  print('${record.$1}: ${record.$2}');

By and large, Records serve the same use cases that package:tuple had been used for. New users coming to this package should likely look at using Dart Records instead. Existing uses of package:tuple will continue to work, however we don't intend to enhance the functionality of this package; we will continue to maintain this package from the POV of bug fixes.

Usage example

const t = Tuple2<String, int>('a', 10);

print(t.item1); // prints 'a'
print(t.item2); // prints '10'
const t1 = Tuple2<String, int>('a', 10);
final t2 = t1.withItem1('c');
// t2 is a new [Tuple2] object with item1 is 'c' and item2 is 10.

tuple.dart's People

Contributors

cenumi avatar dependabot[bot] avatar devoncarew avatar enetor avatar jcollins-g avatar kevmoo avatar linusu avatar srawlins avatar wikiwix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tuple.dart's Issues

Common interface

It would it very convenient to have a common interface for tuple : Tuple

So you can store List but add different implementations.
Currently I need to strongly type on Tuple2 but some result got more entries.

This interface Tuple can gives you the number of index (arity) and allow access to value by index and an iterator.

Thank you !

Should this package be deprecated/unlisted?

With the release of Dart 3.0 comes records. This pretty much does the same as this package, but has more advantages as it is more closely tied in with the other features of the language.

Is this package necessary anymore?

update on package:tuple status

As an update on package:tuple - we consider this package to be feature complete. With Dart 3.0, users now have the ability to use Records:

Records are an anonymous, immutable, aggregate type. Like other collection types, they let you bundle multiple objects into a single object.

  var record = (123, true);
  print('${record.$1}: ${record.$2}');

By and large, Records serve the same use cases that package:tuple had been used for. New users coming to this package should likely look at using Dart Records instead. Existing uses of package:tuple will continue to work, however we don't intend to enhance the functionality of this package; we will continue to maintain this package from the POV of bug fixes.

operator== only checks the generic type

Current implementation of operator== checks the generic type instead of the parameterized type. For example:

class Tuple2<T1, T2> {
  @override
  bool operator ==(other) =>
      other is Tuple2 &&
      other.item1 == item1 &&
      other.item2 == item2;

What is the reason for not checking the parameterized type?

other is Tuple2<T1, T2>

Compatibility with json_serializable

Hi, thank you for your work on tuple!
Is there a recommended way to use tuple together with json_serializable?

For example, if I want to automatically serialize a class that looks like this:

@JsonSerializable(nullable: false)
class Person {
  final String firstName;
  final String lastName;
  final Tuple2<String,int> myTuple;

  Person({this.firstName, this.lastName, this.myTuple});

  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
  Map<String, dynamic> toJson() => _$PersonToJson(this);
}

Loop structure - Helper method

Is there a dynamic approach of calculating the proper TupleX instance to use?

  • If I have an array of 100 elements, I could use 20 instances Tuple5 to make concurrent calls
  • If I have an array of 37 elements, I could use 6 instances of Tuple5 and 1 instance of Tuple7

Question

  • Has anyone gone through this?
  • I depend on collecting the API results of similar tuple instances
    • Parsing an array of same elements

publish the latest contents

We'll need a new publish of this package (as 1.0.3). The pubspec and changelog have already been updated - we just need an uploader to publish the latest bits in master.

@kevmoo is the only uploader, and he's out for a bit.

@mit-mit can either you or @jonasfj upload?

cc @enetor for FYI

Add .cast() methods

Would love to send in a quick PR for this.

Pseudo-code example:

Tuple3 doSomething() native "_doSomething";

void main() {
  var tuple = doSomething.cast<X, Y, Z>(); // Tuple<X, Y, Z>
  // Do something else...
}

class Tuple3 {
  Tuple3<T, U, V> cast<T, U, V>() {
    return Tuple3(item1 as T, item2 as U, item3 as V);
  }
}

[Proposal] Indexing tuples

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'.

  • in case the index is out of bounds, the RangeError is thrown

You could assign me and I would do the PR.

Whats the point of Tuple always being 'const'?

Maybe I'm missing something but I can't pair a with an runtime object as one of the pairs of the tuple since the Tuple2 constructor is const. This completely misses the point then of why you would use a Tuple in the first place. Am I missing something?

e.g.

class Dog
{
String name;
}

enum Action
{
Walk, Wash, Play, Feed
}

void main()
{
var myDog = new Dog();
var myFancyTuple = Tuple2<Dog, Action>(myDog, Action.Feed); <- Invalid since class myDog is not a const.
}

first/second/third/last?

Could Tuple have getters first, second, third, myabe even last, instead of, or less good, in addition to, item{n}?

They could also implement Iterable, though, I'm not sure that would be practically useful, and they'd have to implement Iterable<dynamic> until we have unions and can implement Iterable<A|B|C|D|E>.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.