darq 0.1.2 copy "darq: ^0.1.2" to clipboard
darq: ^0.1.2 copied to clipboard

outdated

The power of lazy-evaluated enumerables in your hands! (A port of functional LINQ from the .NET library.)

pub package

A port of .NET's LINQ IEnumerable functions to Dart. This library adds a powerful Enumerable collection type to Dart that greatly increases convenience when modifying a collection as well as performance when dealing with large collections and complex modifications.

API Reference #

Lazy Execution #

The power of Enumerable is that it supports modification to an underlying collection using lazy execution. This means that the enumerable only stores the data necessary to perform the modification and does not actually perform the modification until the enumerable is iterated over. No data is cached either, so unless you actually iterate over the enumerable, creating one is virtually free from both a memory and performance standpoint.

What's more, when multiple enumerable modifications are chained together, the iteration is done through them all simultaneously. This greatly eases the overhead of performing complex modifications on large collection sets.

Usage #

An Enumerable can be created out of any Dart collection type that extends Iterable. There are two ways to do so:

var sourceList = [0, 1, 2, 3, 4];

// Factory method
var factoryEnum = Enumerable.from(sourceList);

// Convenience method
var convenientEnum = E(sourceList);

You can also generate an Enumerable without needing a pre-existing collection using one of several factory methods:

// Creates an Enumerable with no values
var emptyEnum = Enumerable.empty();

// Creates an Enumerable containing 5 integers starting with the number 2
var rangeEnum = Enumerable.range(2, 5);

// Creates an Enumerable that contains 6 copies of the value 'a string'
var repeatEnum = Enumerable.repeat('a string', 6);

Once you have an Enumerable, you can call any of over 50 different methods on it to modify or analyze it. For example, you can map to a new value with Select:

var myEnum = E([1, 2, 3);
var mappedEnum = myEnum.Select((i) => i * 2);
// Values: [2, 4, 6]

...filter the elements with Where:

var myEnum = E([1, 2, 3);
var filteredEnum = myEnum.Where((i) => i.isOdd);
// Values: [1, 3]

...get only unique values with Distinct:

var myEnum = E([1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 5, 5]);
var uniqueEnum = myEnum.Distinct();
// Values: [1, 2, 3, 4, 5]

...or even group elements together using GroupBy:

var myEnum = E([1, 2, 3, 4, 5, 6]);
var groupedEnum = myEnum.GroupBy((i) => i % 2);
// Values: [[1, 3, 5], [2, 4, 6]]

What's more, you can chain methods together, enabling virtually endless possibilities in a concise chain of method calls:

var myEnum = E([1, 2, 3, 4, 5, 6]);
var resultEnum = myEnum.Select((i) => i * 2)
                       .Where((i) => i > 4)
                       .Select((i) => i.toRadixString(16));
/// Values: ['6', '8', 'A', 'C']

To use the values, you can iterate over the Enumerable just like you would any other Iterable collection:

var myEnum = E([1, 2, 3);
for (var value in myEnum) {
    print(value);
}

// Output:
// 1
// 2
// 3

You can also easily convert the Enumerable back into a Dart collection type using ToList, ToMap, or ToSet:

var myEnum = E([1, 2, 3]);
var myList = myEnum.ToList();
// myList is a List<int> with the values of myEnum

Full Function List #

140
likes
0
pub points
95%
popularity

Publisher

unverified uploader

The power of lazy-evaluated enumerables in your hands! (A port of functional LINQ from the .NET library.)

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on darq