This is a reimagination of Pythons popular Itertools module for C#. Albeit LINQ provides syntactically simple
expressions there is still a few things that Itertools does really well whilst making sense in C#. Most of those
things seem to evolve around the use of tuples or infinite collections. Features for enumerables are
already decently covered in the System.Linq-namespace
.
This app requires .NET Core. PowerShell is optional.
List of features ported.
Type | Nr | Method | Implemented | Comment |
---|---|---|---|---|
Infinite | 1 | count | ✅ | |
Infinite | 2 | cycle | ✅ | |
Infinite | 3 | repeat | - | |
Short termination | 4 | chain | - | |
Short termination | 5 | compress | ✅ | |
Short termination | 6 | dropwhile | ✅ | |
Short termination | 7 | groupby | - | |
Short termination | 8 | filter | ✅ | Also overloads index |
Short termination | 9 | filterfalse | ✅ | Also overloads index |
Short termination | 10 | islice | ✅ | |
Short termination | 11 | map | - | |
Short termination | 12 | starmap | ✅ | |
Short termination | 13 | tee | - | Due to language design return tuple is defined by generics rather than argument. |
Short termination | 14 | takewhile | ✅ | |
Combinatoric | 15 | product | ✅ | |
Combinatoric | 16 | permutations | - | |
Combinatoric | 17 | combinations | 🔨 | |
Combinatoric | 18 | combinations_with_replacements | 🔨 |
This library will probably include a few basic operations in addition to those listed above because of their implied use. However currying, partials and bind will not be included since the have great support through lambdas already.
Bind is already possible so no changes in relation to this:
(i, j) => valueFactory(i, "value0", j);
Currying is achieved with:
i => j => k => valueFactory(i, j, k);
PS> ./make.ps1
PS> ./make.ps1 test
PS> ./make.ps1 run
For example a cartesian product can be described as:
var libraries =
from l in Libraries
join m in Municipalities on l.MunicipalityId equals m.MunicipalityId
from c in Countries
where c.IsoCode equals m.IsoCode || "GP" == c.IsoCode
select l;
Instead it's intended to make use of tuples for applying functions similar to parameter unpacking:
var libraries =
Product(Libraries, Municipalities, Countries)
.Filter((item => item.Item1.MunicipalityId == item.Item2.MunicipalityId)
.Filter(item => item.Item2.IsoCode == item.Item3.IsoCode || "GP" == item.Item3.IsoCode)
.Select(t => t.Item1);