« MoreLINQ » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications
Ligne 11 : Ligne 11 :


= Operators =
= Operators =
== [https://github.com/morelinq/examples/blob/master/m/acquire.md#acquire Acquire] ==
Ensures that a sequence of disposable objects are all acquired successfully.
== [https://github.com/morelinq/examples/blob/master/m/aggregate.md Aggregate] ==
== [https://github.com/morelinq/examples/blob/master/m/aggregate.md Aggregate] ==


== [https://github.com/morelinq/examples/blob/master/m/aggregate-right.md AggregateRight] ==
== Batch ==
This operator is the right-associative version of the Aggregate LINQ operator.
Batches the source sequence into sized buckets.
<kode lang='cs'>
<kode lang='cs'>
// LINQ left-associative aggregate
Enumerable
var result1 = Enumerable
     .Range(1, 10)
     .Range(1, 5)
     .Batch(3); // split the sequence into sequences of max length 3
     .Select(i => i.ToString())
// [1, 2, 3]
    .Aggregate((current, next) => string.Format("({0} > {1})", current, next));
// [4, 5, 6]
// ((((1 > 2) > 3) > 4) > 5)
// [7, 8, 9]
 
// [10]
// MoreLINQ right-associative aggregate
var v2 = Enumerable
    .Range(1, 5)
    .Select(i => i.ToString())
    .AggregateRight((current, next) => string.Format("({0} > {1})", current, next));
// (1 > (2 > (3 > (4 > 5))))
</kode>
</kode>

Version du 14 novembre 2020 à 22:31

Links

Add

Bash.svg
dotnet add package MoreLINQ

Operators

Aggregate

Batch

Batches the source sequence into sized buckets.

Cs.svg
Enumerable
    .Range(1, 10)
    .Batch(3);  // split the sequence into sequences of max length 3
// [1, 2, 3]
// [4, 5, 6]
// [7, 8, 9]
// [10]