GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(infra): add list extensions for replacing a value and moving a value to start index
Lars Berger8e8a802d3ba4
diff --git a/LarsWM.Infrastructure/Utils/ListExtensions.cs b/LarsWM.Infrastructure/Utils/ListExtensions.csnew file mode 100644index 00000000..ccf1eb2c--- /dev/null+++ b/LarsWM.Infrastructure/Utils/ListExtensions.cs@@ -0,0 +1,31 @@+using System.Collections.Generic;++namespace LarsWM.Infrastructure.Utils+{+ public static class ListExtensions+ {+ /// <summary>+ /// Replace the first occurrence of a value with a new value in a list.+ /// </summary>+ public static void Replace<T>(this IList<T> source, T oldValue, T newValue)+ {+ var index = source.IndexOf(oldValue);++ if (index != -1)+ source[index] = newValue;+ }++ /// <summary>+ /// Shift a value to the first index of a list. Insert at start if it doesn't already exist.+ /// </summary>+ public static void MoveToFront<T>(this IList<T> source, T value)+ {+ var initialIndex = source.IndexOf(value);++ if (initialIndex != -1)+ source.Remove(value);++ source.Insert(0, value);+ }+ }+}