diff --git a/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/UtilityExtensions.cs b/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/UtilityExtensions.cs index c698aa7..5a390d6 100644 --- a/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/UtilityExtensions.cs +++ b/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/UtilityExtensions.cs @@ -236,5 +236,53 @@ public static IEnumerable Shuffled(this IEnumerable l, System.Random ra return list; } + + /// + /// Sorts the sequence, yielding a new sorted IEnumerable. + /// Uses List.Sort(). + ///
If the passed IEnumerable is only iterable once it is consumed in the process. + ///
+ public static IEnumerable Sorted(this IEnumerable sequence) + { + var list = sequence.ToList(); + list.Sort(); + return list; + } + + /// + /// Sorts the sequence, yielding a new sorted IEnumerable. + /// Uses List.Sort(IComparer comparer). + ///
If the passed IEnumerable is only iterable once it is consumed in the process. + ///
+ public static IEnumerable Sorted(this IEnumerable sequence, IComparer comparer) + { + var list = sequence.ToList(); + list.Sort(comparer); + return list; + } + + /// + /// Sorts the sequence, yielding a new sorted IEnumerable. + /// Uses List.Sort(Comparison comparison). + ///
If the passed IEnumerable is only iterable once it is consumed in the process. + ///
+ public static IEnumerable Sorted(this IEnumerable sequence, Comparison comparison) + { + var list = sequence.ToList(); + list.Sort(comparison); + return list; + } + + /// + /// Sorts the sequence, yielding a new sorted IEnumerable. + /// Uses List.Sort(int index, int count, IComparer comparer). + ///
If the passed IEnumerable is only iterable once it is consumed in the process. + ///
+ public static IEnumerable Sorted(this IEnumerable sequence, int index, int count, IComparer comparer) + { + var list = sequence.ToList(); + list.Sort(index, count, comparer); + return list; + } } } \ No newline at end of file