EnumerableExtensions - Houzkin/TreeStructures GitHub Wiki
Here, we introduce extension methods for lists.
An extension method for mutable lists, AlignBy compares each element sequentially from the beginning and aligns them similarly to the elements of the specified collection.
The ObservableCollection<T> uses the Move method when elements are moved.
public static void AlignBy<T>(this IList<T> self, IEnumerable<T> org, IEqualityComparer<T>? equality = null);
public static void AlignBy<T>(this ObservableCollection<T> self, IEnumerable<T> org, IEqualityComparer<T>? equality = null);example:
var list = new List<int> { 10, 21, 32, 43, 5, 65, 70, 18, 29 };
list.AlignBy(list.OrderBy(x => x).TakeWile(x => x < 50));
Console.WriteLine(string.Join(", ", list));
// 5, 10, 18, 21, 29, 32, 43Aggregates IDisposable for each element.
public static IDisposable CombineDisposables<T>(this IEnumerable<T> enumerable) where T:IDisposable;Wraps the collection into a state where sorting and filtering can be set.
public static ReadOnlySortFilterObservableCollection<T> ToSortFilterObservable<T>(this ObservableCollection<T> self,IEqualityComparer<T>? equality=null);
public static ReadOnlySortFilterObservableCollection<T> ToSortFilterObservable<T>(this ReadOnlyObservableCollection<T> self,IEqualityComparer<T>? equality = null);Extension methods for Comparer:
Inverts the result of the Comparer.
public static InvertibleComparer<T> Invert<T>(this IComparer<T> self);example:
readonlySortFilterObservable.SortBy(x => x.Comment.Length, Comparer<int>.Default.Invert(), x => x.Comment);