搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案