|
@@ -327,8 +327,11 @@ namespace Invercargill {
|
|
|
|
|
|
public virtual Enumerable<Grouping<TKey, T>> group_by<TKey>(owned TransformDelegate<T, TKey> key_selector, owned EqualityDelegate<TKey>? key_equality = null) {
|
|
public virtual Enumerable<Grouping<TKey, T>> group_by<TKey>(owned TransformDelegate<T, TKey> key_selector, owned EqualityDelegate<TKey>? key_equality = null) {
|
|
var equality = key_equality ?? Operators.equality<TKey>();
|
|
var equality = key_equality ?? Operators.equality<TKey>();
|
|
- var keys = select<TKey>(i => key_selector(i)).distinct((a, b) => equality(a, b));
|
|
|
|
- return keys.select<Grouping<TKey, T>>(g => new Grouping<TKey, T>(g, this.where(i => equality(g, key_selector(i)))));
|
|
|
|
|
|
+ return Iterate.deferred<Grouping<TKey, T>>(() => {
|
|
|
|
+ var items = this.cache();
|
|
|
|
+ var keys = items.select<TKey>(i => key_selector(i)).distinct((a, b) => equality(a, b));
|
|
|
|
+ return keys.select<Grouping<TKey, T>>(g => new Grouping<TKey, T>(g, items.where(i => equality(g, key_selector(i)))));
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
public virtual Enumerable<T> combine_by<TKey>(Enumerable<T> other, owned TransformDelegate<T, TKey> key_selector, owned HashDelegate<TKey>? hash_func = null, owned EqualityDelegate<TKey>? equal_func = null) {
|
|
public virtual Enumerable<T> combine_by<TKey>(Enumerable<T> other, owned TransformDelegate<T, TKey> key_selector, owned HashDelegate<TKey>? hash_func = null, owned EqualityDelegate<TKey>? equal_func = null) {
|
|
@@ -560,6 +563,52 @@ namespace Invercargill {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public virtual Enumerable<Enumerable<T>> chunk(int chunk_size) {
|
|
|
|
+ return new Chunk<T>(this, chunk_size);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<T> cycle(int cycles = -1) {
|
|
|
|
+ return new Cycle<T>(this, cycles);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<Grouping<TKey, T>> group_adjacent_by<TKey>(owned TransformDelegate<T, TKey> key_selector, owned EqualityDelegate<TKey>? key_equality = null) {
|
|
|
|
+ return new GroupSequential<T, TKey>(this, key_selector, key_equality);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<KeyCountPair<TKey>> histogram_by<TKey>(owned TransformDelegate<T, TKey> key_selector, owned EqualityDelegate<TKey>? key_equality = null) {
|
|
|
|
+ var equality = key_equality ?? Operators.equality<TKey>();
|
|
|
|
+ return Iterate.deferred<KeyCountPair<TKey>>(() => {
|
|
|
|
+ var items = this.cache();
|
|
|
|
+ var keys = items.select<TKey>(i => key_selector(i)).distinct((a, b) => equality(a, b));
|
|
|
|
+ return keys.select<KeyCountPair<TKey>>(k => new KeyCountPair<TKey>(k, items.where(i => equality(k, key_selector(i))).count()));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<KeyCountPair<T>> histogram(owned EqualityDelegate<T>? key_equality = null) {
|
|
|
|
+ return histogram_by<T>(i => i, (owned)key_equality);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<T> reverse() {
|
|
|
|
+ return new Reverse<T>(this);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<Enumerable<T>> window(uint window_size) {
|
|
|
|
+ return new Window<T>(this, window_size);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<T> pad_end(uint minimum_length, T pad_item) {
|
|
|
|
+ return new Padding<T>(this, pad_item, minimum_length);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<T> pad_start(uint minimum_length, T pad_item) {
|
|
|
|
+ // This is cursed
|
|
|
|
+ return reverse().pad_end(minimum_length, pad_item).reverse();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public virtual Enumerable<TOut> scan<TOut>(TOut initial_value, owned AggregateDelegate<T, TOut> scanning_delegate) {
|
|
|
|
+ return new Modifiers.Scanner<T, TOut>(this, initial_value, (owned)scanning_delegate);
|
|
|
|
+ }
|
|
|
|
+
|
|
public virtual void debug_dump(string additional_message = "", StringifyDelegate<T>? stringifier = null, DebugOutputDelegate? output_func = null, bool formatting = true) {
|
|
public virtual void debug_dump(string additional_message = "", StringifyDelegate<T>? stringifier = null, DebugOutputDelegate? output_func = null, bool formatting = true) {
|
|
DebugPrinter.print_enumerable_dump<T>(this, stringifier, additional_message, output_func, formatting);
|
|
DebugPrinter.print_enumerable_dump<T>(this, stringifier, additional_message, output_func, formatting);
|
|
}
|
|
}
|