@@ -449,19 +449,9 @@ private static IEnumerable<string> ToStringsCore<T>(IEnumerable<T> source)
449
449
/// <c>true</c>, if <paramref name="source"/> has at least one element and first element is equals to
450
450
/// <paramref name="item"/>, otherwise <c>false</c>.
451
451
/// </returns>
452
- public static bool IsFirst < TSource > ( [ NotNull ] this IEnumerable < TSource > source , TSource item )
453
- {
454
- Code . NotNull ( source , nameof ( source ) ) ;
455
-
456
- // Fast path
457
- // ReSharper disable once CollectionNeverUpdated.Local
458
- if ( source is IList < TSource > list )
459
- return Equals ( item , list [ 0 ] ) ;
460
-
461
- foreach ( var current in source )
462
- return Equals ( item , current ) ;
463
- return false ;
464
- }
452
+ [ Pure ]
453
+ public static bool IsFirst < TSource > ( [ NotNull ] this IEnumerable < TSource > source , TSource item ) =>
454
+ source . IsFirst ( item , EqualityComparer < TSource > . Default ) ;
465
455
466
456
/// <summary>
467
457
/// Checks, if <paramref name="item"/> is first element of <paramref name="source"/>.
@@ -474,6 +464,7 @@ public static bool IsFirst<TSource>([NotNull] this IEnumerable<TSource> source,
474
464
/// <c>true</c>, if <paramref name="source"/> has at least one element and first element is equals to
475
465
/// <paramref name="item"/>, otherwise <c>false</c>.
476
466
/// </returns>
467
+ [ Pure ]
477
468
public static bool IsFirst < TSource > (
478
469
[ NotNull ] this IEnumerable < TSource > source ,
479
470
TSource item ,
@@ -503,28 +494,9 @@ public static bool IsFirst<TSource>(
503
494
/// <c>true</c>, if <paramref name="source"/> has at least one element and last element is equals to
504
495
/// <paramref name="item"/>, otherwise <c>false</c>.
505
496
/// </returns>
506
- public static bool IsLast < TSource > ( [ NotNull ] this IEnumerable < TSource > source , TSource item )
507
- {
508
- Code . NotNull ( source , nameof ( source ) ) ;
509
-
510
- // Fast path
511
- // ReSharper disable once CollectionNeverUpdated.Local
512
- if ( source is IList < TSource > list )
513
- return Equals ( item , list [ list . Count - 1 ] ) ;
514
-
515
- using ( var en = source . GetEnumerator ( ) )
516
- if ( en . MoveNext ( ) )
517
- {
518
- TSource current ;
519
- do
520
- {
521
- current = en . Current ;
522
- } while ( en . MoveNext ( ) ) ;
523
- return Equals ( item , current ) ;
524
- }
525
- else
526
- return false ;
527
- }
497
+ [ Pure ]
498
+ public static bool IsLast < TSource > ( [ NotNull ] this IEnumerable < TSource > source , TSource item ) =>
499
+ source . IsLast ( item , EqualityComparer < TSource > . Default ) ;
528
500
529
501
/// <summary>
530
502
/// Checks, if <paramref name="item"/> is last element of <paramref name="source"/>.
@@ -537,6 +509,7 @@ public static bool IsLast<TSource>([NotNull] this IEnumerable<TSource> source, T
537
509
/// <c>true</c>, if <paramref name="source"/> has at least one element and last element is equals to
538
510
/// <paramref name="item"/>, otherwise <c>false</c>.
539
511
/// </returns>
512
+ [ Pure ]
540
513
public static bool IsLast < TSource > (
541
514
[ NotNull ] this IEnumerable < TSource > source ,
542
515
TSource item ,
0 commit comments