diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3c9ce..5374a68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.0.14] - 2024-12-22 +- Add Filter extension method for IList + ## [1.0.13] - 2024-12-01 - Add more `Task` and `Reflection` Extension methods. diff --git a/UnityUtils/Scripts/Extensions/ListExtensions.cs b/UnityUtils/Scripts/Extensions/ListExtensions.cs index 2e1037c..1dc721f 100644 --- a/UnityUtils/Scripts/Extensions/ListExtensions.cs +++ b/UnityUtils/Scripts/Extensions/ListExtensions.cs @@ -60,5 +60,22 @@ public static IList Shuffle(this IList list) { } return list; } + + /// + /// Filters a collection based on a predicate and returns a new list + /// containing the elements that match the specified condition. + /// + /// The collection to filter. + /// The condition that each element is tested against. + /// A new list containing elements that satisfy the predicate. + public static IList Filter(this IList source, Predicate predicate) { + List list = new List(); + foreach (T item in source) { + if (predicate(item)) { + list.Add(item); + } + } + return list; + } } } diff --git a/package.json b/package.json index b9d95bc..bb38266 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.gitamend.unityutils", "displayName": "Unity Utility Library", "description": "Unity Utility Library, a growing collection of handy extension methods, helpers, attributes, and other utilities designed to enhance and simplify your Unity development workflow. Whether you're a seasoned developer or just starting, this library aims to provide tools that will help streamline your coding process and add efficiency to your projects.", - "version": "1.0.13", + "version": "1.0.14", "keywords": [ "extension", "attribute",