ktx

Last updated:

0 purchases

ktx Image
ktx Images
Add to Cart

Description:

ktx

KTX #




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
mapToList
sortBy
groupBy
mapIndexed
zip
let


associateBy #
associateBy is an operation allows associate the list items with the given key.
final List<Fruit> fruits = [
Fruit(id: 1, kind: "Pear", color: "Red"),
Fruit(id: 2, kind: "Apple", color: "Green")
];
final Map<int, Fruit> mappedFruits = fruits
.associateBy((fruit) => fruit.id);
copied to clipboard

mapToList #
mapToList returns a list containing the results of applying the given [transform] function.
final Map<int, Fruit> fruits = {
1: Fruit(kind: "Pear", color: "Red"),
2: Fruit(kind: "Apple", color: "Green")
};
final List<String> fruitNames = fruits
.mapToList((key, fruit) => fruit.kind);
copied to clipboard

sortBy #
sortBy sorts elements in the list in-place according to natural sort order of the value returned by specified [selector] function.
final List<Fruit> fruits = [
Fruit(id: 1, kind: "Apple", color: "Red"),
Fruit(id: 2, kind: "Apple", color: "Green")
];
final List<Fruit> sortedByNamefruits = fruits
.sortBy((fruit) => fruit.kind);
copied to clipboard

groupBy #
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<Fruit> fruits = [
Fruit(id: 1, kind: "Apple", color: "Red"),
Fruit(id: 2, kind: "Apple", color: "Green")
];
final Map<String, List<Fruit>> groupedFruits = fruits
.groupBy((fruit) => fruit.kind);
copied to clipboard

mapIndexed #
mapIndexed returns a list containing the results of applying the given [transform] function to each element and its index in the original collection.
final fruits = ["Apple", "Pear", "Orange"];
final indexedFruits = fruits.mapIndexed((index, fruit) => "${index + 1}: $fruit");

/// ["1: Apple", "2: Pear", "3: Orange"]);
copied to clipboard

zip #
zip returns a list of values built from the elements of this collection and the [other] collection with the same index.
final kinds = ["Apple", "Pear", "Apricot"];
final colors = ["Red", "Green", "Orange"];
final fruits = kinds.zip(colors, (kind, color) => Fruit(kind, color));
copied to clipboard

let #
let calls the specified function [block] with this value as its argument and returns its result.
final Fruit? fruit = Fruit(id: 1, kind: "Apple", color: "Red");
fruit?.let((fruit) => print(fruit));
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.