ktx 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

KTX #

pub

The KTX Library provides a comprehensive set of tools for managing collections – groups of a variable number of items (possibly zero) that share significance to the problem being solved and are operated upon commonly.

Getting Started #

associateBy is an operation allows associate the list items with the given key.

final List<User> users = [
    User(id: 1, firstName: "Dmytro", lastName: "Glynskyi"),
    User(id: 2, firstName: "Vladimir", lastName: "Zelenskyi")
];
final Map<int, User> mappedUsers = users
    .associateBy((user) => user.id);

mapToList returns a list containing the results of applying the given [transform] function.

final Map<int, User> users = {
  1: User(firstName: "Dmytro", lastName: "Glynskyi"),
  2: User(firstName: "Vladimir", lastName: "Zelenskyi")
};
final List<String> userName = users
    .mapToList((key, user) => user.firstName);

sortBy sorts elements in the list in-place according to natural sort order of the value returned by specified [selector] function.

final List<User> users = [
    User(id: 1, firstName: "Vladimir", lastName: "Glynskyi"),
    User(id: 2, firstName: "Vladimir", lastName: "Zelenskyi")
];
final List<User> sortedByNameUsers = users
    .sortBy((user) => user.firstName);

groupBy groups elements of the original collection by the key returned by the given [keySelector] function applied to each element and returns a map where each group key is associated with a list of corresponding elements.

final List<User> users = [
    User(id: 1, firstName: "Vladimir", lastName: "Glynskyi"),
    User(id: 2, firstName: "Vladimir", lastName: "Zelenskyi")
];
final Map<String, List<User>> groupedUsers = users
    .groupBy((user) => user.firstName);

1.0.6 #

  • Added mapNotNull function

1.0.5 #

  • Added groupBy function

1.0.4 #

  • Added sortBy function
  • Added sortByDescending function

1.0.2 #

  • Changed mapToList signature for convenience

1.0.1 #

  • Added mapToList function

1.0.0 #

  • Stabilized the collections API

0.0.3 #

  • Upgraded the SDK restrictions

0.0.2 #

  • Added an example for associateBy function

0.0.1 #

  • Added associateBy function

example/example.dart

import 'package:ktx/ktx.dart';

void main() {
  final numbers = [1, 2, 3];
  final map = numbers.associateBy((number) => number);
  print(map);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ktx: ^1.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ktx/ktx.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.7

Health suggestions

Format lib/collections.dart.

Run dartfmt to format lib/collections.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
Dev dependencies
http_multi_server ^2.2.0
test ^1.9.2