Skip to content

Commit

Permalink
Add IList Filter method
Browse files Browse the repository at this point in the history
  • Loading branch information
adammyhre committed Dec 22, 2024
1 parent 021fbbb commit 0aff54f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
17 changes: 17 additions & 0 deletions UnityUtils/Scripts/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,22 @@ public static IList<T> Shuffle<T>(this IList<T> list) {
}
return list;
}

/// <summary>
/// Filters a collection based on a predicate and returns a new list
/// containing the elements that match the specified condition.
/// </summary>
/// <param name="source">The collection to filter.</param>
/// <param name="predicate">The condition that each element is tested against.</param>
/// <returns>A new list containing elements that satisfy the predicate.</returns>
public static IList<T> Filter<T>(this IList<T> source, Predicate<T> predicate) {
List<T> list = new List<T>();
foreach (T item in source) {
if (predicate(item)) {
list.Add(item);
}
}
return list;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0aff54f

Please sign in to comment.