패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.2

flinq

컬렉션에 대한 확장된 기능입니다. 컬렉션 작업 시 불필요한 반복 코드를 피하기 위한 단축키 모음입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.9천
좋아요
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 개

소스 저장소

이 패키지를 사용하는 프로젝트