搜索插件、代码仓与 APP 分类

插件详情v2.0.2

tuple

一个提供元组数据结构的库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
150万
喜欢数
484
Pub 分数
140

安装插件

flutter pub add tuple

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

元组包为 Dart 提供了一种轻量级、类型安全的元组数据结构,可将多个可能类型不同的值组合成一个单一的不可变对象。它最多支持 7 个元素,并提供了直观的语法用于创建、访问和解构。该库设计简洁且性能优异,在无需定义自定义类的情况下,能够清晰地返回或传递多个相关值。该库特别适用于函数式编程模式以及需要简洁数据聚合的场景。

适合场景

  • 从函数返回多个值
  • 在方法之间传递分组数据
  • 函数式编程模式
  • 简化状态管理中的数据传输
  • 避免小型数据结构的样板代码

主要特点

  • 不可变元组对象
  • 元素间的类型安全性
  • 支持最多 7 个元素
  • 通过模式匹配进行解构
  • 最小的运行时开销
  • 创建和访问的简洁语法

适合对象

  • 寻求轻量级数据容器的开发者
  • 使用函数式编程风格的项目
  • 需要高效多值返回的应用程序
  • 避免为简单数据定义自定义类
  • 跨平台应用,针对所有主要平台

使用建议

  • 限制为7个元素
  • 不适合大型或复杂的数据模型
  • 不可变性可能需要为可变用例提供替代方案
  • 对于新开发人员来说,不如命名类易于发现

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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.

所属分类

源码仓库

使用此插件的项目