@@ -67,7 +67,8 @@ public static T[] Concat<T>(this T[] array, T[] elements)
6767 /// <param name="array">The array to search in.</param>
6868 /// <param name="element">The element to search for.</param>
6969 /// <returns>True if the array contains the element, false otherwise.</returns>
70- public static bool Contains < T > ( this T [ ] array , T element ) where T : IEquatable < T >
70+ public static bool Contains < T > ( this T [ ] array , T element )
71+ where T : IEquatable < T >
7172 {
7273 for ( int i = 0 ; i < array . Length ; i ++ )
7374 {
@@ -79,6 +80,44 @@ public static bool Contains<T>(this T[] array, T element) where T : IEquatable<T
7980 return false ;
8081 }
8182
83+ /// <summary>
84+ /// Checks if the array contains an element that satisfies a predicate.
85+ /// </summary>
86+ /// <typeparam name="T">The type of the array.</typeparam>
87+ /// <param name="array">The array to search in.</param>
88+ /// <param name="predicate">The predicate to use.</param>
89+ /// <returns>True if any element satisfies the predicate.</returns>
90+ public static bool Contains < T > ( this T [ ] array , Predicate < T > predicate )
91+ {
92+ for ( int i = 0 ; i < array . Length ; i ++ )
93+ {
94+ if ( predicate ( array [ i ] ) == true ) {
95+ return true ;
96+ }
97+ }
98+
99+ return false ;
100+ }
101+
102+ /// <summary>
103+ /// Checks if the array contains all elements that satisfy a predicate.
104+ /// </summary>
105+ /// <typeparam name="T">The type of the array.</typeparam>
106+ /// <param name="array">The array to search in.</param>
107+ /// <param name="predicate">The predicate to use.</param>
108+ /// <returns>True if all elements satisfy the predicate.</returns>
109+ public static bool ContainsAll < T > ( this T [ ] array , Predicate < T > predicate )
110+ {
111+ for ( int i = 0 ; i < array . Length ; i ++ )
112+ {
113+ if ( predicate ( array [ i ] ) == false ) {
114+ return false ;
115+ }
116+ }
117+
118+ return true ;
119+ }
120+
82121 /// <summary>
83122 /// Returns the element at the specified index.
84123 /// </summary>
@@ -263,7 +302,8 @@ public static void ForEach<T>(this T[] array, Action<T> action)
263302 /// <param name="array">The array to search in.</param>
264303 /// <param name="element">The element to search for.</param>
265304 /// <returns>The index of the element in the array.</returns>
266- public static int IndexOf < T > ( this T [ ] array , T element ) where T : IEquatable < T >
305+ public static int IndexOf < T > ( this T [ ] array , T element )
306+ where T : IEquatable < T >
267307 {
268308 for ( int i = 0 ; i < array . Length ; i ++ )
269309 {
@@ -276,41 +316,23 @@ public static int IndexOf<T>(this T[] array, T element) where T : IEquatable<T>
276316 }
277317
278318 /// <summary>
279- /// Checks if any element in the array satisfies a predicate.
319+ /// Returns the index of the first element in the array that satisfies
320+ /// the predicate.
280321 /// </summary>
281322 /// <typeparam name="T">The type of the array.</typeparam>
282323 /// <param name="array">The array to search in.</param>
283324 /// <param name="predicate">The predicate to use.</param>
284- /// <returns>True if any element satisfies the predicate .</returns>
285- public static bool IsAny < T > ( this T [ ] array , Predicate < T > predicate )
325+ /// <returns>The index of the element, or -1 if not found .</returns>
326+ public static int IndexOf < T > ( this T [ ] array , Predicate < T > predicate )
286327 {
287328 for ( int i = 0 ; i < array . Length ; i ++ )
288329 {
289330 if ( predicate ( array [ i ] ) == true ) {
290- return true ;
291- }
292- }
293-
294- return false ;
295- }
296-
297- /// <summary>
298- /// Checks if each element in the array satisfies a predicate.
299- /// </summary>
300- /// <typeparam name="T">The type of the array.</typeparam>
301- /// <param name="array">The array to search in.</param>
302- /// <param name="predicate">The predicate to use.</param>
303- /// <returns>True if all elements satisfy the predicate.</returns>
304- public static bool IsEach < T > ( this T [ ] array , Predicate < T > predicate )
305- {
306- for ( int i = 0 ; i < array . Length ; i ++ )
307- {
308- if ( predicate ( array [ i ] ) == false ) {
309- return false ;
331+ return i ;
310332 }
311333 }
312334
313- return true ;
335+ return - 1 ;
314336 }
315337
316338 /// <summary>
0 commit comments