EnumerableExtensions - Houzkin/TreeStructures GitHub Wiki

Here, we introduce extension methods for lists.

AlignBy

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, 43

CombineDisposables

Aggregates IDisposable for each element.

public static IDisposable CombineDisposables<T>(this IEnumerable<T> enumerable) where T:IDisposable;

ToSortFilterObservable

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);

Comparer

Extension methods for Comparer:

Invert

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);
⚠️ **GitHub.com Fallback** ⚠️