パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.2

flinq

コレクションの拡張機能。コレクション操作における不要なボイラープレートコードを回避するためのショートカット群です。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1900
いいね数
57
Pub ポイント
150

パッケージをインストール

flutter pub add flinq

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flinq は、ボイラープレートコードを削減する直感的な拡張メソッドのセットにより、Dart のコレクション処理を強化します。フィルタリング、マッピング、コレクションの変換などの一般的な操作に対して便利なショートカットを提供し、リストやセットとの作業をより簡潔かつ読みやすくします。軽量ユーティリティとして設計されており、既存のDartプロジェクトに複雑さを加えずにシームレスに統合されます。繰り返し発生するコレクション操作の簡略化を通じて、開発者の生産性を向上させることに焦点を当てています。

用途

  • リスト変換の簡素化
  • データ処理におけるボイラープレートの削減
  • フィルタリングおよびマッピング論理の簡素化
  • コードの可読性を向上させる
  • 関数型スタイルのコレクション操作の強化
  • プロトタイピングの高速化

主な機能

  • チェーン可能な拡張メソッド
  • 最小限の構文オーバーヘッド
  • すべての主要なコレクション型をサポートしています
  • 外部の依存関係なし
  • 洗練された機能的API設計
  • 直感的なメソッド名の付け方

適している対象

  • よりクリーンなコレクションコードを求めるDart開発者
  • コードの明確さに焦点を当てるプロジェクト
  • Dartにおける関数型プログラミングパターン
  • 迅速なアプリケーション開発
  • 繰り返しコードを減らそうとしているチーム

注意事項

  • コレクション操作に限定
  • 複雑な状態管理には適していない
  • Dart拡張の知識が必要です
  • 初心者にとって学習曲線が上がる可能性があります
  • 他のユーティリティと併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

flinq

Build codecov Pub GitHub GitHub stars

Extended capabilities for collections. It's a bunch of shortcuts to avoid unnecesary boilerplate work with collections.

Getting Started

This package will help you to reduce the amount of boilerplate code by adding folowing extensions for Iterables:

  • getter firstOrNull and method firstOrNullWhere for getting first value, and if it will not be found returns null

  • getter lastOrNull and method lastOrNullWhere for getting last value, and if it will not be found returns null

  • getter singleOrNull and method singleOrNullWhere for getting single value, and if it will not be found returns null, and if there will be too many elements it'll also return null

  • method mapList, which maps collection and casts it to List

  • method whereList, which filters collection and casts it to List

  • method mapWhereList, which maps collection, then filters it and then casts it to List

  • method whereMapList, which filters collection, then maps collection and then casts it to List

  • getter notNull for getting only not null values from the collection

  • method group and groupMap for grouping a collection

  • getter min/minOrNull and max/maxOrNull for getting minimal or maximal value from collection of Comparables

  • method minWhere/minOrNullWhere and maxWhere/maxOrNullWhere for getting minimal or maximal value from filtered collection of Comparables

  • getter sum and average for getting sum and average from collection of nums

  • method sumWhere and averageWhere for getting sum and average from filtered collection of nums

  • getter distinct and method distinctWhere which will return List with unique values in collection

  • method union and unionWhere which will return List with union of two collections with only unique values in resulting collection

  • method intersection and intersectionWhere which will return List with elements that contains both collections with only unique values in resulting collection

  • method difference and differenceWhere which will return List with difference between two collections with only unique values in resulting collection

Examples

Iterable extension can be used like this:

Common
  • firstOrNull and firstOrNullWhere
final firstOrNull = [].firstOrNull; // null
// or
final firstOrNull = [3, 6, 2, 7, 9].firstOrNullWhere((item) => item > 10); // null
  • lastOrNull and lastOrNullWhere
final lastOrNull = [].lastOrNull; // null
// or
final lastOrNull = [3, 6, 2, 7, 9].lastOrNullWhere((item) => item > 10); // null
  • singleOrNull and singleOrNullWhere
final singleOrNull = [].singleOrNull; // null
// or
final singleOrNull = [3, 6, 2, 7, 9].singleOrNullWhere((item) => item > 3); // null
  • mapList
List<double> mappedList = [3, 6, 2, 7, 9].mapList((item) => item.toDouble());
  • whereList
List<int> filteredList = [3, 6, 2, 7, 9].whereList((item) => item > 4);
  • whereMapList
List<double> filteredMappedList = [3, 6, 2, 7, 9].whereMapList((item) => item > 4, (item) => item.toDouble());
  • mapWhereList
List<double> mappedFilteredList = [3, 6, 2, 7, 9].mapWhereList((item) => item.toDouble(), (item) => item > 4);
  • notNull
Iterable<int> notNullIterable = [3, 6, 2, null, 7, 9].notNull;
  • group
final collection = [
    Pet("rat", "Mike"),
    Pet("dog", "Rex"),
    Pet("cat", "Lucy"),
];

/*
<bool, List<Pet>>{
    true: [
        Pet("rat", "Mike"),
        Pet("cat", "Lucy"),
    ],
    false: [
        Pet("dog", "Rex"),
    ],
}
*/
final group = collection.group((item) => item.name.endsWith('at'));
  • groupMap
final collection = [
    Pet("rat", "Mike"),
    Pet("dog", "Rex"),
    Pet("cat", "Lucy"),
];

/*
<bool, int>{
    true: 2,
    false: 1,
}
*/
final groupMapped = collection.groupMap(
      (item) => item.name.endsWith('at'), (group) => group.length);
Comparable
  • min and minOrNull
final min = [3, 6, 2, 7, 9].min; // 2
// or
final min = [].minOrNull; // null
  • minWhere and minOrNullWhere
final min = [3, 6, 2, 7, 9].minWhere((_) => _ > 4); // 6
// or
final min = [3, 2].minOrNullWhere((_) => _ > 4); // null
  • max and maxOrNull
final max = [3, 6, 2, 7, 9].max; // 9
// or
final max = [].maxOrNull; // null
  • maxWhere and maxOrNullWhere
final max = [3, 6, 2, 7, 9].maxWhere((_) => _ < 4); // 3
// or
final max = [3, 2].maxOrNullWhere((_) => _ > 4); // null
Math
  • sum
final sum = [3, 6, 2, 7, 9].sum; // 27
  • average
final average = [1, 3, 5, 7, 4, 4].average; // 4
  • sumWhere
final sum = [3, 6, 2, 7, 9].sumWhere((_) => _ > 4); // 22
  • averageWhere
final average = [1, 3, 5, 7, 4, 4].averageWhere((_) => _ > 4); // 6
Set
  • distinct
final collectionOne = [2, 5, 8, 2];

final distinctCollection = collectionOne.distinct; // [2, 5, 8]
  • distinctWhere
final collectionOne = [2, 5, 8, 2];

final distinctCollection = collectionOne.distinctWhere((_) => _ > 4); // [5, 8]
  • union
final collectionOne = [2, 5, 8, 2];
final collectionTwo = [1, 3, 5, 7];

final unitedCollection = collectionOne.union(collectionTwo); // [2, 5, 8, 1, 3, 7]
  • unionWhere
final collectionOne = [2, 5, 8, 2];
final collectionTwo = [1, 3, 5, 7];

final unitedCollection = collectionOne.unionWhere(collectionTwo, (_) => _ > 4); // [5, 8, 7]
  • intersection
final collectionOne = [2, 5, 8, 2];
final collectionTwo = [1, 3, 5, 7];

final intersectedCollection = collectionOne.intersection(collectionTwo); // [5]
  • intersectionWhere
final collectionOne = [2, 5, 8, 2];
final collectionTwo = [1, 3, 5, 7];

final intersectedCollection = collectionOne.intersectionWhere(collectionTwo, (_) => _ < 4); // []
  • difference
final collectionOne = [2, 5, 8, 2];
final collectionTwo = [1, 3, 5, 7];

final differedCollection = collectionOne.difference(collectionTwo); // [2, 8]
// or
final differedCollection = collectionTwo.difference(collectionOne); // [1, 3, 7]
  • differenceWhere
final collectionOne = [2, 5, 8, 2];
final collectionTwo = [1, 3, 5, 7];

final differedCollection = collectionOne.differenceWhere(collectionTwo, (_) => _ < 4); // [2]
// or
final differedCollection = collectionTwo.differenceWhere(collectionOne, (_) => _ < 4); // [1, 3]

Feature requests and Bug reports

Feel free to post a feature requests or report a bug here.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト