@@ -16,6 +16,27 @@ public static void AddUnlessNullOrEmpty(this ICollection<Expression> items, Expr
1616 }
1717 }
1818
19+ [ DebuggerStepThrough ]
20+ public static T First < T > ( this IList < T > items ) => items [ 0 ] ;
21+
22+ public static T First < T > ( this IList < T > items , Func < T , bool > predicate )
23+ {
24+ for ( int i = 0 , n = items . Count ; i < n ; i ++ )
25+ {
26+ var item = items [ i ] ;
27+
28+ if ( predicate . Invoke ( item ) )
29+ {
30+ return item ;
31+ }
32+ }
33+
34+ throw new InvalidOperationException ( "Sequence contains no matching element" ) ;
35+ }
36+
37+ [ DebuggerStepThrough ]
38+ public static T Last < T > ( this IList < T > items ) => items [ items . Count - 1 ] ;
39+
1940 [ DebuggerStepThrough ]
2041 public static bool Any < T > ( this ICollection < T > items ) => items . Count > 0 ;
2142
@@ -41,7 +62,7 @@ public static bool None<T>(this IEnumerable<T> items, Func<T, bool> predicate)
4162 [ DebuggerStepThrough ]
4263 public static bool HasOne < T > ( this ICollection < T > items ) => items . Count == 1 ;
4364
44- public static Expression ReverseChain < T > ( this ICollection < T > items )
65+ public static Expression ReverseChain < T > ( this IList < T > items )
4566 where T : IConditionallyChainable
4667 {
4768 return ReverseChain (
@@ -66,27 +87,27 @@ private static Expression AddPreConditionIfNecessary(IConditionallyChainable ite
6687 }
6788
6889 public static Expression ReverseChain < TItem > (
69- this ICollection < TItem > items ,
90+ this IList < TItem > items ,
7091 Func < TItem , Expression > seedValueFactory ,
7192 Func < Expression , TItem , Expression > itemValueFactory )
7293 {
7394 return Chain ( items , i => i . Last ( ) , seedValueFactory , itemValueFactory , i => i . Reverse ( ) ) ;
7495 }
7596
7697 public static Expression Chain < TItem > (
77- this ICollection < TItem > items ,
98+ this IList < TItem > items ,
7899 Func < TItem , Expression > seedValueFactory ,
79100 Func < Expression , TItem , Expression > itemValueFactory )
80101 {
81102 return Chain ( items , i => i . First ( ) , seedValueFactory , itemValueFactory , i => i ) ;
82103 }
83104
84105 private static Expression Chain < TItem > (
85- ICollection < TItem > items ,
86- Func < ICollection < TItem > , TItem > seedFactory ,
106+ IList < TItem > items ,
107+ Func < IList < TItem > , TItem > seedFactory ,
87108 Func < TItem , Expression > seedValueFactory ,
88109 Func < Expression , TItem , Expression > itemValueFactory ,
89- Func < ICollection < TItem > , IEnumerable < TItem > > initialOperation )
110+ Func < IList < TItem > , IEnumerable < TItem > > initialOperation )
90111 {
91112 if ( items . None ( ) )
92113 {
0 commit comments