Search packages, repositories and app categories

Package detailsv2.0.2

tuple

A library providing a tuple data structure.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
1.5M
Likes
484
Pub points
140

Install package

flutter pub add tuple

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The tuple package provides a lightweight, type-safe tuple data structure for Dart, enabling the grouping of multiple values of potentially different types into a single immutable object. It supports up to 7 elements and offers intuitive syntax for creation, access, and destructuring. Designed for simplicity and performance, it enhances code clarity when returning or passing multiple related values without defining custom classes. The library is particularly useful in functional programming patterns and scenarios requiring concise data aggregation.

Use cases

  • Returning multiple values from functions
  • Passing grouped data between methods
  • Functional programming patterns
  • Simplifying data transfer in state management
  • Avoiding boilerplate for small data structures

Key features

  • Immutable tuple objects
  • Type safety across elements
  • Support for up to 7 elements
  • Destructuring via pattern matching
  • Minimal runtime overhead
  • Clean syntax for creation and access

Suitable for

  • Developers seeking lightweight data containers
  • Projects using functional programming styles
  • Apps needing efficient multi-value returns
  • Teams avoiding custom class definitions for simple data
  • Cross-platform apps targeting all major platforms

Considerations

  • Limited to 7 elements
  • Not suitable for large or complex data models
  • Immutability may require workarounds for mutable use cases
  • Less discoverable than named classes for new developers

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package