forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move classes into separate files. Split Enumerable among several files. Remove redundant references to generic types or namespaces. Fixes #1149
- Loading branch information
Showing
43 changed files
with
6,086 additions
and
5,583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace System.Linq | ||
{ | ||
public static partial class Enumerable | ||
{ | ||
public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func) | ||
{ | ||
if (source == null) throw Error.ArgumentNull("source"); | ||
if (func == null) throw Error.ArgumentNull("func"); | ||
using (IEnumerator<TSource> e = source.GetEnumerator()) | ||
{ | ||
if (!e.MoveNext()) throw Error.NoElements(); | ||
TSource result = e.Current; | ||
while (e.MoveNext()) result = func(result, e.Current); | ||
return result; | ||
} | ||
} | ||
|
||
public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func) | ||
{ | ||
if (source == null) throw Error.ArgumentNull("source"); | ||
if (func == null) throw Error.ArgumentNull("func"); | ||
TAccumulate result = seed; | ||
foreach (TSource element in source) result = func(result, element); | ||
return result; | ||
} | ||
|
||
public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector) | ||
{ | ||
if (source == null) throw Error.ArgumentNull("source"); | ||
if (func == null) throw Error.ArgumentNull("func"); | ||
if (resultSelector == null) throw Error.ArgumentNull("resultSelector"); | ||
TAccumulate result = seed; | ||
foreach (TSource element in source) result = func(result, element); | ||
return resultSelector(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace System.Linq | ||
{ | ||
public static partial class Enumerable | ||
{ | ||
public static bool Any<TSource>(this IEnumerable<TSource> source) | ||
{ | ||
if (source == null) throw Error.ArgumentNull("source"); | ||
using (IEnumerator<TSource> e = source.GetEnumerator()) | ||
{ | ||
return e.MoveNext(); | ||
} | ||
} | ||
|
||
public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) | ||
{ | ||
if (source == null) throw Error.ArgumentNull("source"); | ||
if (predicate == null) throw Error.ArgumentNull("predicate"); | ||
foreach (TSource element in source) | ||
{ | ||
if (predicate(element)) return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) | ||
{ | ||
if (source == null) throw Error.ArgumentNull("source"); | ||
if (predicate == null) throw Error.ArgumentNull("predicate"); | ||
foreach (TSource element in source) | ||
{ | ||
if (!predicate(element)) return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.