|
@@ -255,13 +255,19 @@ namespace Invercargill {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public virtual Enumerable<T> distinct(owned EqualityDelegate<T> comparison) {
|
|
|
- return new UniqueQuery<T>(this, (owned)comparison);
|
|
|
+ public virtual Enumerable<T> distinct(owned EqualityDelegate<T>? comparison = null) {
|
|
|
+ return distinct_by<T>(i => i, (owned)comparison);
|
|
|
}
|
|
|
|
|
|
- public virtual Enumerable<Grouping<TKey, T>> group_by<TKey>(TransformDelegate<T, TKey> key_selector, EqualityDelegate<TKey> key_equality) {
|
|
|
- var keys = select<TKey>(i => key_selector(i)).distinct((a, b) => key_equality(a, b));
|
|
|
- return keys.select<Grouping<TKey, T>>(g => new Grouping<TKey, T>(g, this.where(i => key_equality(g, key_selector(i)))));
|
|
|
+ public virtual Enumerable<T> distinct_by<TProp>(owned TransformDelegate<T, TProp> property_selector, owned EqualityDelegate<TProp>? property_equality) {
|
|
|
+ var func = property_equality ?? Operators.equality<T>();
|
|
|
+ return new UniqueByQuery<T, TProp>(this, (owned)property_selector, (owned)func);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 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)))));
|
|
|
}
|
|
|
|
|
|
public virtual Enumerable<T> @with(T item, uint times = 1) {
|