diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..bdb0cabc8
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,17 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
diff --git a/MoreLinq.sln b/MoreLinq.sln
index 0924ab172..f9c1c67d6 100644
--- a/MoreLinq.sln
+++ b/MoreLinq.sln
@@ -1,95 +1,95 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30501.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{835F8FFA-471F-4322-B721-A897F27872FA}"
- ProjectSection(SolutionItems) = preProject
- build.cmd = build.cmd
- buildw.cmd = buildw.cmd
- COPYING.txt = COPYING.txt
- pkg\morelinq.nuspec = pkg\morelinq.nuspec
- pack.cmd = pack.cmd
- packw.cmd = packw.cmd
- EndProjectSection
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq", "MoreLinq\MoreLinq.csproj", "{8642E81B-3414-4C13-914F-05A4E600FE49}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq.Test", "MoreLinq.Test\MoreLinq.Test.csproj", "{D89B7AF5-7615-47B7-B894-A722E66DB3D8}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuspecs", "Nuspecs", "{55D09D94-E557-4383-B5DB-9F15D43DAC72}"
- ProjectSection(SolutionItems) = preProject
- pkg\morelinq.nuspec = pkg\morelinq.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Acquire.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Acquire.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.AssertCount.nuspec = pkg\MoreLinq.Source.MoreEnumerable.AssertCount.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Batch.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Batch.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Concat.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Concat.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Consume.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Consume.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.DistinctBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.DistinctBy.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.EquiZip.nuspec = pkg\MoreLinq.Source.MoreEnumerable.EquiZip.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.ExceptBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ExceptBy.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Fold.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Fold.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.ForEach.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ForEach.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Generate.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Generate.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.GenerateByIndex.nuspec = pkg\MoreLinq.Source.MoreEnumerable.GenerateByIndex.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.GroupAdjacent.nuspec = pkg\MoreLinq.Source.MoreEnumerable.GroupAdjacent.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Index.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Index.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.MaxBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.MaxBy.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.MinBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.MinBy.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.nuspec = pkg\MoreLinq.Source.MoreEnumerable.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.OrderedMerge.nuspec = pkg\MoreLinq.Source.MoreEnumerable.OrderedMerge.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Pad.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Pad.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Pairwise.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Pairwise.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Pipe.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Pipe.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Prepend.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Prepend.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.PreScan.nuspec = pkg\MoreLinq.Source.MoreEnumerable.PreScan.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Scan.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Scan.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.SingleOrFallback.nuspec = pkg\MoreLinq.Source.MoreEnumerable.SingleOrFallback.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.SkipUntil.nuspec = pkg\MoreLinq.Source.MoreEnumerable.SkipUntil.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Split.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Split.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.TakeEvery.nuspec = pkg\MoreLinq.Source.MoreEnumerable.TakeEvery.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.TakeLast.nuspec = pkg\MoreLinq.Source.MoreEnumerable.TakeLast.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.TakeUntil.nuspec = pkg\MoreLinq.Source.MoreEnumerable.TakeUntil.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.ToDataTable.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ToDataTable.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.ToDelimitedString.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ToDelimitedString.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.ToHashSet.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ToHashSet.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Trace.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Trace.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.Zip.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Zip.nuspec
- pkg\MoreLinq.Source.MoreEnumerable.ZipLongest.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ZipLongest.nuspec
- pkg\MoreLinq.Portable.nuspec = pkg\MoreLinq.Portable.nuspec
- EndProjectSection
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq.Portable", "MoreLinq\MoreLinq.Portable.csproj", "{72C49B06-715D-4423-AD0A-78517F71D7B9}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq.Portable.Test", "MoreLinq.Test\MoreLinq.Portable.Test.csproj", "{3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {8642E81B-3414-4C13-914F-05A4E600FE49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8642E81B-3414-4C13-914F-05A4E600FE49}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8642E81B-3414-4C13-914F-05A4E600FE49}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8642E81B-3414-4C13-914F-05A4E600FE49}.Release|Any CPU.Build.0 = Release|Any CPU
- {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Release|Any CPU.Build.0 = Release|Any CPU
- {72C49B06-715D-4423-AD0A-78517F71D7B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {72C49B06-715D-4423-AD0A-78517F71D7B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {72C49B06-715D-4423-AD0A-78517F71D7B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {72C49B06-715D-4423-AD0A-78517F71D7B9}.Release|Any CPU.Build.0 = Release|Any CPU
- {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- VisualSVNWorkingCopyRoot =
- EndGlobalSection
-EndGlobal
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.30501.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{835F8FFA-471F-4322-B721-A897F27872FA}"
+ ProjectSection(SolutionItems) = preProject
+ build.cmd = build.cmd
+ buildw.cmd = buildw.cmd
+ COPYING.txt = COPYING.txt
+ pkg\morelinq.nuspec = pkg\morelinq.nuspec
+ pack.cmd = pack.cmd
+ packw.cmd = packw.cmd
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq", "MoreLinq\MoreLinq.csproj", "{8642E81B-3414-4C13-914F-05A4E600FE49}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq.Test", "MoreLinq.Test\MoreLinq.Test.csproj", "{D89B7AF5-7615-47B7-B894-A722E66DB3D8}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuspecs", "Nuspecs", "{55D09D94-E557-4383-B5DB-9F15D43DAC72}"
+ ProjectSection(SolutionItems) = preProject
+ pkg\morelinq.nuspec = pkg\morelinq.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Acquire.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Acquire.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.AssertCount.nuspec = pkg\MoreLinq.Source.MoreEnumerable.AssertCount.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Batch.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Batch.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Concat.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Concat.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Consume.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Consume.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.DistinctBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.DistinctBy.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.EquiZip.nuspec = pkg\MoreLinq.Source.MoreEnumerable.EquiZip.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.ExceptBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ExceptBy.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Fold.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Fold.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.ForEach.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ForEach.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Generate.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Generate.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.GenerateByIndex.nuspec = pkg\MoreLinq.Source.MoreEnumerable.GenerateByIndex.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.GroupAdjacent.nuspec = pkg\MoreLinq.Source.MoreEnumerable.GroupAdjacent.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Index.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Index.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.MaxBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.MaxBy.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.MinBy.nuspec = pkg\MoreLinq.Source.MoreEnumerable.MinBy.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.nuspec = pkg\MoreLinq.Source.MoreEnumerable.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.OrderedMerge.nuspec = pkg\MoreLinq.Source.MoreEnumerable.OrderedMerge.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Pad.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Pad.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Pairwise.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Pairwise.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Pipe.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Pipe.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Prepend.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Prepend.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.PreScan.nuspec = pkg\MoreLinq.Source.MoreEnumerable.PreScan.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Scan.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Scan.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.SingleOrFallback.nuspec = pkg\MoreLinq.Source.MoreEnumerable.SingleOrFallback.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.SkipUntil.nuspec = pkg\MoreLinq.Source.MoreEnumerable.SkipUntil.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Split.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Split.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.TakeEvery.nuspec = pkg\MoreLinq.Source.MoreEnumerable.TakeEvery.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.TakeLast.nuspec = pkg\MoreLinq.Source.MoreEnumerable.TakeLast.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.TakeUntil.nuspec = pkg\MoreLinq.Source.MoreEnumerable.TakeUntil.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.ToDataTable.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ToDataTable.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.ToDelimitedString.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ToDelimitedString.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.ToHashSet.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ToHashSet.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Trace.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Trace.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.Zip.nuspec = pkg\MoreLinq.Source.MoreEnumerable.Zip.nuspec
+ pkg\MoreLinq.Source.MoreEnumerable.ZipLongest.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ZipLongest.nuspec
+ pkg\MoreLinq.Portable.nuspec = pkg\MoreLinq.Portable.nuspec
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq.Portable", "MoreLinq\MoreLinq.Portable.csproj", "{72C49B06-715D-4423-AD0A-78517F71D7B9}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreLinq.Portable.Test", "MoreLinq.Test\MoreLinq.Portable.Test.csproj", "{3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {8642E81B-3414-4C13-914F-05A4E600FE49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8642E81B-3414-4C13-914F-05A4E600FE49}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8642E81B-3414-4C13-914F-05A4E600FE49}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8642E81B-3414-4C13-914F-05A4E600FE49}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D89B7AF5-7615-47B7-B894-A722E66DB3D8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {72C49B06-715D-4423-AD0A-78517F71D7B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {72C49B06-715D-4423-AD0A-78517F71D7B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {72C49B06-715D-4423-AD0A-78517F71D7B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {72C49B06-715D-4423-AD0A-78517F71D7B9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3A47BCE6-B1A4-467A-BAF0-3021ED39FC7D}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ VisualSVNWorkingCopyRoot =
+ EndGlobalSection
+EndGlobal
diff --git a/MoreLinq/Acquire.cs b/MoreLinq/Acquire.cs
index 8d1eee4ce..09d8e2d45 100644
--- a/MoreLinq/Acquire.cs
+++ b/MoreLinq/Acquire.cs
@@ -1,60 +1,60 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Ensures that a source sequence of
- /// objects are all acquired successfully. If the acquisition of any
- /// one fails then those successfully
- /// acquired till that point are disposed.
- ///
- /// Type of elements in sequence.
- /// Source sequence of objects.
- ///
- /// Returns an array of all the acquired
- /// object and in source order.
- ///
- ///
- /// This operator executes immediately.
- ///
-
- public static TSource[] Acquire(this IEnumerable source)
- where TSource : IDisposable
- {
- if (source == null) throw new ArgumentNullException("source");
-
- var disposables = new List();
- try
- {
- disposables.AddRange(source);
- return disposables.ToArray();
- }
- catch
- {
- foreach (var disposable in disposables)
- disposable.Dispose();
- throw;
- }
- }
- }
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Ensures that a source sequence of
+ /// objects are all acquired successfully. If the acquisition of any
+ /// one fails then those successfully
+ /// acquired till that point are disposed.
+ ///
+ /// Type of elements in sequence.
+ /// Source sequence of objects.
+ ///
+ /// Returns an array of all the acquired
+ /// object and in source order.
+ ///
+ ///
+ /// This operator executes immediately.
+ ///
+
+ public static TSource[] Acquire(this IEnumerable source)
+ where TSource : IDisposable
+ {
+ if (source == null) throw new ArgumentNullException("source");
+
+ var disposables = new List();
+ try
+ {
+ disposables.AddRange(source);
+ return disposables.ToArray();
+ }
+ catch
+ {
+ foreach (var disposable in disposables)
+ disposable.Dispose();
+ throw;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/MoreLinq/AssertCount.cs b/MoreLinq/AssertCount.cs
index 1f97920b1..d9e5b4753 100644
--- a/MoreLinq/AssertCount.cs
+++ b/MoreLinq/AssertCount.cs
@@ -1,124 +1,124 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- #if MORELINQ
-
- private static readonly Func defaultErrorSelector = OnAssertCountFailure;
-
- ///
- /// Asserts that a source sequence contains a given count of elements.
- ///
- /// Type of elements in sequence.
- /// Source sequence.
- /// Count to assert.
- ///
- /// Returns the original sequence as long it is contains the
- /// number of elements specified by .
- /// Otherwise it throws .
- ///
- ///
- /// This operator uses deferred execution and streams its results.
- ///
-
- public static IEnumerable AssertCount(this IEnumerable source,
- int count)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (count < 0) throw new ArgumentOutOfRangeException("count");
-
- return AssertCountImpl(source, count, defaultErrorSelector);
- }
-
- ///
- /// Asserts that a source sequence contains a given count of elements.
- /// A parameter specifies the exception to be thrown.
- ///
- /// Type of elements in sequence.
- /// Source sequence.
- /// Count to assert.
- /// Function that returns the object to throw.
- ///
- /// Returns the original sequence as long it is contains the
- /// number of elements specified by .
- /// Otherwise it throws the object
- /// returned by calling .
- ///
- ///
- /// This operator uses deferred execution and streams its results.
- ///
-
- public static IEnumerable AssertCount(this IEnumerable source,
- int count, Func errorSelector)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (count < 0) throw new ArgumentException(null, "count");
- if (errorSelector == null) throw new ArgumentNullException("errorSelector");
-
- return AssertCountImpl(source, count, errorSelector);
- }
-
- private static Exception OnAssertCountFailure(int cmp, int count)
- {
- var message = cmp < 0
- ? "Sequence contains too few elements when exactly {0} were expected."
- : "Sequence contains too many elements when exactly {0} were expected.";
- return new SequenceException(string.Format(message, count.ToString("N0")));
- }
-
- #endif
-
- private static IEnumerable AssertCountImpl(IEnumerable source,
- int count, Func errorSelector)
- {
- var collection = source as ICollection; // Optimization for collections
- if (collection != null)
- {
- if (collection.Count != count)
- throw errorSelector(collection.Count.CompareTo(count), count);
- return source;
- }
-
- return ExpectingCountYieldingImpl(source, count, errorSelector);
- }
-
- private static IEnumerable ExpectingCountYieldingImpl(IEnumerable source,
- int count, Func errorSelector)
- {
- var iterations = 0;
- foreach (var element in source)
- {
- iterations++;
- if (iterations > count)
- {
- throw errorSelector(1, count);
- }
- yield return element;
- }
- if (iterations != count)
- {
- throw errorSelector(-1, count);
- }
- }
- }
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ #if MORELINQ
+
+ private static readonly Func defaultErrorSelector = OnAssertCountFailure;
+
+ ///
+ /// Asserts that a source sequence contains a given count of elements.
+ ///
+ /// Type of elements in sequence.
+ /// Source sequence.
+ /// Count to assert.
+ ///
+ /// Returns the original sequence as long it is contains the
+ /// number of elements specified by .
+ /// Otherwise it throws .
+ ///
+ ///
+ /// This operator uses deferred execution and streams its results.
+ ///
+
+ public static IEnumerable AssertCount(this IEnumerable source,
+ int count)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ if (count < 0) throw new ArgumentOutOfRangeException("count");
+
+ return AssertCountImpl(source, count, defaultErrorSelector);
+ }
+
+ ///
+ /// Asserts that a source sequence contains a given count of elements.
+ /// A parameter specifies the exception to be thrown.
+ ///
+ /// Type of elements in sequence.
+ /// Source sequence.
+ /// Count to assert.
+ /// Function that returns the object to throw.
+ ///
+ /// Returns the original sequence as long it is contains the
+ /// number of elements specified by .
+ /// Otherwise it throws the object
+ /// returned by calling .
+ ///
+ ///
+ /// This operator uses deferred execution and streams its results.
+ ///
+
+ public static IEnumerable AssertCount(this IEnumerable source,
+ int count, Func errorSelector)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ if (count < 0) throw new ArgumentException(null, "count");
+ if (errorSelector == null) throw new ArgumentNullException("errorSelector");
+
+ return AssertCountImpl(source, count, errorSelector);
+ }
+
+ private static Exception OnAssertCountFailure(int cmp, int count)
+ {
+ var message = cmp < 0
+ ? "Sequence contains too few elements when exactly {0} were expected."
+ : "Sequence contains too many elements when exactly {0} were expected.";
+ return new SequenceException(string.Format(message, count.ToString("N0")));
+ }
+
+ #endif
+
+ private static IEnumerable AssertCountImpl(IEnumerable source,
+ int count, Func errorSelector)
+ {
+ var collection = source as ICollection; // Optimization for collections
+ if (collection != null)
+ {
+ if (collection.Count != count)
+ throw errorSelector(collection.Count.CompareTo(count), count);
+ return source;
+ }
+
+ return ExpectingCountYieldingImpl(source, count, errorSelector);
+ }
+
+ private static IEnumerable ExpectingCountYieldingImpl(IEnumerable source,
+ int count, Func errorSelector)
+ {
+ var iterations = 0;
+ foreach (var element in source)
+ {
+ iterations++;
+ if (iterations > count)
+ {
+ throw errorSelector(1, count);
+ }
+ yield return element;
+ }
+ if (iterations != count)
+ {
+ throw errorSelector(-1, count);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/MoreLinq/Batch.cs b/MoreLinq/Batch.cs
index 8c21f2683..bf3ee71c3 100644
--- a/MoreLinq/Batch.cs
+++ b/MoreLinq/Batch.cs
@@ -1,100 +1,100 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
-
- static partial class MoreEnumerable
- {
- ///
- /// Batches the source sequence into sized buckets.
- ///
- /// Type of elements in sequence.
- /// The source sequence.
- /// Size of buckets.
- /// A sequence of equally sized buckets containing elements of the source collection.
- /// This operator uses deferred execution and streams its results (buckets and bucket content).
-
- public static IEnumerable> Batch(this IEnumerable source, int size)
- {
- return Batch(source, size, x => x);
- }
-
- ///
- /// Batches the source sequence into sized buckets and applies a projection to each bucket.
- ///
- /// Type of elements in sequence.
- /// Type of result returned by .
- /// The source sequence.
- /// Size of buckets.
- /// The projection to apply to each bucket.
- /// A sequence of projections on equally sized buckets containing elements of the source collection.
- /// This operator uses deferred execution and streams its results (buckets and bucket content).
-
- public static IEnumerable Batch(this IEnumerable source, int size,
- Func, TResult> resultSelector)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (size <= 0) throw new ArgumentOutOfRangeException("size");
- if (resultSelector == null) throw new ArgumentNullException("resultSelector");
- return BatchImpl(source, size, resultSelector);
- }
-
- private static IEnumerable BatchImpl(this IEnumerable source, int size,
- Func, TResult> resultSelector)
- {
- Debug.Assert(source != null);
- Debug.Assert(size > 0);
- Debug.Assert(resultSelector != null);
-
- TSource[] bucket = null;
- var count = 0;
-
- foreach (var item in source)
- {
- if (bucket == null)
- {
- bucket = new TSource[size];
- }
-
- bucket[count++] = item;
-
- // The bucket is fully buffered before it's yielded
- if (count != size)
- {
- continue;
- }
-
- // Select is necessary so bucket contents are streamed too
- yield return resultSelector(bucket.Select(x => x));
-
- bucket = null;
- count = 0;
- }
-
- // Return the last bucket with all remaining elements
- if (bucket != null && count > 0)
- {
- yield return resultSelector(bucket.Take(count));
- }
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Linq;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Batches the source sequence into sized buckets.
+ ///
+ /// Type of elements in sequence.
+ /// The source sequence.
+ /// Size of buckets.
+ /// A sequence of equally sized buckets containing elements of the source collection.
+ /// This operator uses deferred execution and streams its results (buckets and bucket content).
+
+ public static IEnumerable> Batch(this IEnumerable source, int size)
+ {
+ return Batch(source, size, x => x);
+ }
+
+ ///
+ /// Batches the source sequence into sized buckets and applies a projection to each bucket.
+ ///
+ /// Type of elements in sequence.
+ /// Type of result returned by .
+ /// The source sequence.
+ /// Size of buckets.
+ /// The projection to apply to each bucket.
+ /// A sequence of projections on equally sized buckets containing elements of the source collection.
+ /// This operator uses deferred execution and streams its results (buckets and bucket content).
+
+ public static IEnumerable Batch(this IEnumerable source, int size,
+ Func, TResult> resultSelector)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ if (size <= 0) throw new ArgumentOutOfRangeException("size");
+ if (resultSelector == null) throw new ArgumentNullException("resultSelector");
+ return BatchImpl(source, size, resultSelector);
+ }
+
+ private static IEnumerable BatchImpl(this IEnumerable source, int size,
+ Func, TResult> resultSelector)
+ {
+ Debug.Assert(source != null);
+ Debug.Assert(size > 0);
+ Debug.Assert(resultSelector != null);
+
+ TSource[] bucket = null;
+ var count = 0;
+
+ foreach (var item in source)
+ {
+ if (bucket == null)
+ {
+ bucket = new TSource[size];
+ }
+
+ bucket[count++] = item;
+
+ // The bucket is fully buffered before it's yielded
+ if (count != size)
+ {
+ continue;
+ }
+
+ // Select is necessary so bucket contents are streamed too
+ yield return resultSelector(bucket.Select(x => x));
+
+ bucket = null;
+ count = 0;
+ }
+
+ // Return the last bucket with all remaining elements
+ if (bucket != null && count > 0)
+ {
+ yield return resultSelector(bucket.Take(count));
+ }
+ }
+ }
+}
diff --git a/MoreLinq/Concat.cs b/MoreLinq/Concat.cs
index e5ffc5423..37ebe355d 100644
--- a/MoreLinq/Concat.cs
+++ b/MoreLinq/Concat.cs
@@ -1,57 +1,57 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-using LinqEnumerable = System.Linq.Enumerable;
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Returns a sequence consisting of the head element and the given tail elements.
- ///
- /// Type of sequence
- /// Head element of the new sequence.
- /// All elements of the tail. Must not be null.
- /// A sequence consisting of the head elements and the given tail elements.
- /// This operator uses deferred execution and streams its results.
-
- public static IEnumerable Concat(this T head, IEnumerable tail)
- {
- if (tail == null) throw new ArgumentNullException("tail");
- return tail.Prepend(head);
- }
-
- ///
- /// Returns a sequence consisting of the head elements and the given tail element.
- ///
- /// Type of sequence
- /// All elements of the head. Must not be null.
- /// Tail element of the new sequence.
- /// A sequence consisting of the head elements and the given tail element.
- /// This operator uses deferred execution and streams its results.
-
- public static IEnumerable Concat(this IEnumerable head, T tail)
- {
- if (head == null) throw new ArgumentNullException("head");
- return LinqEnumerable.Concat(head, LinqEnumerable.Repeat(tail, 1));
- }
- }
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+using LinqEnumerable = System.Linq.Enumerable;
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Returns a sequence consisting of the head element and the given tail elements.
+ ///
+ /// Type of sequence
+ /// Head element of the new sequence.
+ /// All elements of the tail. Must not be null.
+ /// A sequence consisting of the head elements and the given tail elements.
+ /// This operator uses deferred execution and streams its results.
+
+ public static IEnumerable Concat(this T head, IEnumerable tail)
+ {
+ if (tail == null) throw new ArgumentNullException("tail");
+ return tail.Prepend(head);
+ }
+
+ ///
+ /// Returns a sequence consisting of the head elements and the given tail element.
+ ///
+ /// Type of sequence
+ /// All elements of the head. Must not be null.
+ /// Tail element of the new sequence.
+ /// A sequence consisting of the head elements and the given tail element.
+ /// This operator uses deferred execution and streams its results.
+
+ public static IEnumerable Concat(this IEnumerable head, T tail)
+ {
+ if (head == null) throw new ArgumentNullException("head");
+ return LinqEnumerable.Concat(head, LinqEnumerable.Repeat(tail, 1));
+ }
+ }
}
\ No newline at end of file
diff --git a/MoreLinq/Consume.cs b/MoreLinq/Consume.cs
index 2690c5a45..dce393516 100644
--- a/MoreLinq/Consume.cs
+++ b/MoreLinq/Consume.cs
@@ -1,40 +1,40 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Completely consumes the given sequence. This method uses immediate execution,
- /// and doesn't store any data during execution.
- ///
- /// Element type of the sequence
- /// Source to consume
-
- public static void Consume(this IEnumerable source)
- {
- if (source == null) throw new ArgumentNullException("source");
- foreach (var element in source)
- {
- }
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Completely consumes the given sequence. This method uses immediate execution,
+ /// and doesn't store any data during execution.
+ ///
+ /// Element type of the sequence
+ /// Source to consume
+
+ public static void Consume(this IEnumerable source)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ foreach (var element in source)
+ {
+ }
+ }
+ }
+}
diff --git a/MoreLinq/DistinctBy.cs b/MoreLinq/DistinctBy.cs
index 60710d32b..08609df33 100644
--- a/MoreLinq/DistinctBy.cs
+++ b/MoreLinq/DistinctBy.cs
@@ -1,103 +1,103 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-
-#if NO_HASHSET
-using System.Linq;
-#endif
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Returns all distinct elements of the given source, where "distinctness"
- /// is determined via a projection and the default equality comparer for the projected type.
- ///
- ///
- /// This operator uses deferred execution and streams the results, although
- /// a set of already-seen keys is retained. If a key is seen multiple times,
- /// only the first element with that key is returned.
- ///
- /// Type of the source sequence
- /// Type of the projected element
- /// Source sequence
- /// Projection for determining "distinctness"
- /// A sequence consisting of distinct elements from the source sequence,
- /// comparing them by the specified key projection.
-
- public static IEnumerable DistinctBy(this IEnumerable source,
- Func keySelector)
- {
- return source.DistinctBy(keySelector, null);
- }
-
- ///
- /// Returns all distinct elements of the given source, where "distinctness"
- /// is determined via a projection and the specified comparer for the projected type.
- ///
- ///
- /// This operator uses deferred execution and streams the results, although
- /// a set of already-seen keys is retained. If a key is seen multiple times,
- /// only the first element with that key is returned.
- ///
- /// Type of the source sequence
- /// Type of the projected element
- /// Source sequence
- /// Projection for determining "distinctness"
- /// The equality comparer to use to determine whether or not keys are equal.
- /// If null, the default equality comparer for TSource is used.
- /// A sequence consisting of distinct elements from the source sequence,
- /// comparing them by the specified key projection.
-
- public static IEnumerable DistinctBy(this IEnumerable source,
- Func keySelector, IEqualityComparer comparer)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (keySelector == null) throw new ArgumentNullException("keySelector");
- return DistinctByImpl(source, keySelector, comparer);
- }
-
- private static IEnumerable DistinctByImpl(IEnumerable source,
- Func keySelector, IEqualityComparer comparer)
- {
-#if !NO_HASHSET
- var knownKeys = new HashSet(comparer);
- foreach (var element in source)
- {
- if (knownKeys.Add(keySelector(element)))
- {
- yield return element;
- }
- }
-#else
- //
- // On platforms where LINQ is available but no HashSet
- // (like on Silverlight), implement this operator using
- // existing LINQ operators. Using GroupBy is slightly less
- // efficient since it has do all the grouping work before
- // it can start to yield any one element from the source.
- //
-
- return source.GroupBy(keySelector, comparer).Select(g => g.First());
-#endif
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+
+#if NO_HASHSET
+using System.Linq;
+#endif
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Returns all distinct elements of the given source, where "distinctness"
+ /// is determined via a projection and the default equality comparer for the projected type.
+ ///
+ ///
+ /// This operator uses deferred execution and streams the results, although
+ /// a set of already-seen keys is retained. If a key is seen multiple times,
+ /// only the first element with that key is returned.
+ ///
+ /// Type of the source sequence
+ /// Type of the projected element
+ /// Source sequence
+ /// Projection for determining "distinctness"
+ /// A sequence consisting of distinct elements from the source sequence,
+ /// comparing them by the specified key projection.
+
+ public static IEnumerable DistinctBy(this IEnumerable source,
+ Func keySelector)
+ {
+ return source.DistinctBy(keySelector, null);
+ }
+
+ ///
+ /// Returns all distinct elements of the given source, where "distinctness"
+ /// is determined via a projection and the specified comparer for the projected type.
+ ///
+ ///
+ /// This operator uses deferred execution and streams the results, although
+ /// a set of already-seen keys is retained. If a key is seen multiple times,
+ /// only the first element with that key is returned.
+ ///
+ /// Type of the source sequence
+ /// Type of the projected element
+ /// Source sequence
+ /// Projection for determining "distinctness"
+ /// The equality comparer to use to determine whether or not keys are equal.
+ /// If null, the default equality comparer for TSource is used.
+ /// A sequence consisting of distinct elements from the source sequence,
+ /// comparing them by the specified key projection.
+
+ public static IEnumerable DistinctBy(this IEnumerable source,
+ Func keySelector, IEqualityComparer comparer)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ if (keySelector == null) throw new ArgumentNullException("keySelector");
+ return DistinctByImpl(source, keySelector, comparer);
+ }
+
+ private static IEnumerable DistinctByImpl(IEnumerable source,
+ Func keySelector, IEqualityComparer comparer)
+ {
+#if !NO_HASHSET
+ var knownKeys = new HashSet(comparer);
+ foreach (var element in source)
+ {
+ if (knownKeys.Add(keySelector(element)))
+ {
+ yield return element;
+ }
+ }
+#else
+ //
+ // On platforms where LINQ is available but no HashSet
+ // (like on Silverlight), implement this operator using
+ // existing LINQ operators. Using GroupBy is slightly less
+ // efficient since it has do all the grouping work before
+ // it can start to yield any one element from the source.
+ //
+
+ return source.GroupBy(keySelector, comparer).Select(g => g.First());
+#endif
+ }
+ }
+}
diff --git a/MoreLinq/EquiZip.cs b/MoreLinq/EquiZip.cs
index 486892a33..38f068ab1 100644
--- a/MoreLinq/EquiZip.cs
+++ b/MoreLinq/EquiZip.cs
@@ -1,80 +1,80 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Returns a projection of tuples, where each tuple contains the N-th element
- /// from each of the argument sequences.
- ///
- ///
- /// If the two input sequences are of different lengths then
- /// is thrown.
- /// This operator uses deferred execution and streams its results.
- ///
- ///
- ///
- /// int[] numbers = { 1, 2, 3, 4 };
- /// string[] letters = { "A", "B", "C", "D" };
- /// var zipped = numbers.EquiZip(letters, (n, l) => n + l);
- ///
- /// The zipped variable, when iterated over, will yield "1A", "2B", "3C", "4D" in turn.
- ///
- /// Type of elements in first sequence
- /// Type of elements in second sequence
- /// Type of elements in result sequence
- /// First sequence
- /// Second sequence
- /// Function to apply to each pair of elements
-
- public static IEnumerable EquiZip(this IEnumerable first,
- IEnumerable second,
- Func resultSelector)
- {
- if (first == null) throw new ArgumentNullException("first");
- if (second == null) throw new ArgumentNullException("second");
- if (resultSelector == null) throw new ArgumentNullException("resultSelector");
-
- return EquiZipImpl(first, second, resultSelector);
- }
-
- static IEnumerable EquiZipImpl(
- IEnumerable first,
- IEnumerable second,
- Func resultSelector)
- {
- using (var e1 = first.GetEnumerator())
- using (var e2 = second.GetEnumerator())
- {
- while (e1.MoveNext())
- {
- if (e2.MoveNext())
- yield return resultSelector(e1.Current, e2.Current);
- else
- throw new InvalidOperationException("Second sequence ran out before first");
- }
- if (e2.MoveNext())
- throw new InvalidOperationException("First sequence ran out before second");
- }
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Returns a projection of tuples, where each tuple contains the N-th element
+ /// from each of the argument sequences.
+ ///
+ ///
+ /// If the two input sequences are of different lengths then
+ /// is thrown.
+ /// This operator uses deferred execution and streams its results.
+ ///
+ ///
+ ///
+ /// int[] numbers = { 1, 2, 3, 4 };
+ /// string[] letters = { "A", "B", "C", "D" };
+ /// var zipped = numbers.EquiZip(letters, (n, l) => n + l);
+ ///
+ /// The zipped variable, when iterated over, will yield "1A", "2B", "3C", "4D" in turn.
+ ///
+ /// Type of elements in first sequence
+ /// Type of elements in second sequence
+ /// Type of elements in result sequence
+ /// First sequence
+ /// Second sequence
+ /// Function to apply to each pair of elements
+
+ public static IEnumerable EquiZip(this IEnumerable first,
+ IEnumerable second,
+ Func resultSelector)
+ {
+ if (first == null) throw new ArgumentNullException("first");
+ if (second == null) throw new ArgumentNullException("second");
+ if (resultSelector == null) throw new ArgumentNullException("resultSelector");
+
+ return EquiZipImpl(first, second, resultSelector);
+ }
+
+ static IEnumerable EquiZipImpl(
+ IEnumerable first,
+ IEnumerable second,
+ Func resultSelector)
+ {
+ using (var e1 = first.GetEnumerator())
+ using (var e2 = second.GetEnumerator())
+ {
+ while (e1.MoveNext())
+ {
+ if (e2.MoveNext())
+ yield return resultSelector(e1.Current, e2.Current);
+ else
+ throw new InvalidOperationException("Second sequence ran out before first");
+ }
+ if (e2.MoveNext())
+ throw new InvalidOperationException("First sequence ran out before second");
+ }
+ }
+ }
+}
diff --git a/MoreLinq/ExceptBy.cs b/MoreLinq/ExceptBy.cs
index 76ba9fea8..0de05fbeb 100644
--- a/MoreLinq/ExceptBy.cs
+++ b/MoreLinq/ExceptBy.cs
@@ -1,102 +1,102 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
-
- static partial class MoreEnumerable
- {
- ///
- /// Returns the set of elements in the first sequence which aren't
- /// in the second sequence, according to a given key selector.
- ///
- ///
- /// This is a set operation; if multiple elements in have
- /// equal keys, only the first such element is returned.
- /// This operator uses deferred execution and streams the results, although
- /// a set of keys from is immediately selected and retained.
- ///
- /// The type of the elements in the input sequences.
- /// The type of the key returned by .
- /// The sequence of potentially included elements.
- /// The sequence of elements whose keys may prevent elements in
- /// from being returned.
- /// The mapping from source element to key.
- /// A sequence of elements from whose key was not also a key for
- /// any element in .
-
- public static IEnumerable ExceptBy(this IEnumerable first,
- IEnumerable second,
- Func keySelector)
- {
- return ExceptBy(first, second, keySelector, null);
- }
-
- ///
- /// Returns the set of elements in the first sequence which aren't
- /// in the second sequence, according to a given key selector.
- ///
- ///
- /// This is a set operation; if multiple elements in have
- /// equal keys, only the first such element is returned.
- /// This operator uses deferred execution and streams the results, although
- /// a set of keys from is immediately selected and retained.
- ///
- /// The type of the elements in the input sequences.
- /// The type of the key returned by .
- /// The sequence of potentially included elements.
- /// The sequence of elements whose keys may prevent elements in
- /// from being returned.
- /// The mapping from source element to key.
- /// The equality comparer to use to determine whether or not keys are equal.
- /// If null, the default equality comparer for TSource is used.
- /// A sequence of elements from whose key was not also a key for
- /// any element in .
-
- public static IEnumerable ExceptBy(this IEnumerable first,
- IEnumerable second,
- Func keySelector,
- IEqualityComparer keyComparer)
- {
- if (first == null) throw new ArgumentNullException("first");
- if (second == null) throw new ArgumentNullException("second");
- if (keySelector == null) throw new ArgumentNullException("keySelector");
- return ExceptByImpl(first, second, keySelector, keyComparer);
- }
-
- private static IEnumerable ExceptByImpl(this IEnumerable first,
- IEnumerable second,
- Func keySelector,
- IEqualityComparer keyComparer)
- {
- var keys = new HashSet(second.Select(keySelector), keyComparer);
- foreach (var element in first)
- {
- var key = keySelector(element);
- if (keys.Contains(key))
- {
- continue;
- }
- yield return element;
- keys.Add(key);
- }
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Returns the set of elements in the first sequence which aren't
+ /// in the second sequence, according to a given key selector.
+ ///
+ ///
+ /// This is a set operation; if multiple elements in have
+ /// equal keys, only the first such element is returned.
+ /// This operator uses deferred execution and streams the results, although
+ /// a set of keys from is immediately selected and retained.
+ ///
+ /// The type of the elements in the input sequences.
+ /// The type of the key returned by .
+ /// The sequence of potentially included elements.
+ /// The sequence of elements whose keys may prevent elements in
+ /// from being returned.
+ /// The mapping from source element to key.
+ /// A sequence of elements from whose key was not also a key for
+ /// any element in .
+
+ public static IEnumerable ExceptBy(this IEnumerable first,
+ IEnumerable second,
+ Func keySelector)
+ {
+ return ExceptBy(first, second, keySelector, null);
+ }
+
+ ///
+ /// Returns the set of elements in the first sequence which aren't
+ /// in the second sequence, according to a given key selector.
+ ///
+ ///
+ /// This is a set operation; if multiple elements in have
+ /// equal keys, only the first such element is returned.
+ /// This operator uses deferred execution and streams the results, although
+ /// a set of keys from is immediately selected and retained.
+ ///
+ /// The type of the elements in the input sequences.
+ /// The type of the key returned by .
+ /// The sequence of potentially included elements.
+ /// The sequence of elements whose keys may prevent elements in
+ /// from being returned.
+ /// The mapping from source element to key.
+ /// The equality comparer to use to determine whether or not keys are equal.
+ /// If null, the default equality comparer for TSource is used.
+ /// A sequence of elements from whose key was not also a key for
+ /// any element in .
+
+ public static IEnumerable ExceptBy(this IEnumerable first,
+ IEnumerable second,
+ Func keySelector,
+ IEqualityComparer keyComparer)
+ {
+ if (first == null) throw new ArgumentNullException("first");
+ if (second == null) throw new ArgumentNullException("second");
+ if (keySelector == null) throw new ArgumentNullException("keySelector");
+ return ExceptByImpl(first, second, keySelector, keyComparer);
+ }
+
+ private static IEnumerable ExceptByImpl(this IEnumerable first,
+ IEnumerable second,
+ Func keySelector,
+ IEqualityComparer keyComparer)
+ {
+ var keys = new HashSet(second.Select(keySelector), keyComparer);
+ foreach (var element in first)
+ {
+ var key = keySelector(element);
+ if (keys.Contains(key))
+ {
+ continue;
+ }
+ yield return element;
+ keys.Add(key);
+ }
+ }
+ }
+}
diff --git a/MoreLinq/Fold.cs b/MoreLinq/Fold.cs
index 77a96fdbc..50d512e70 100644
--- a/MoreLinq/Fold.cs
+++ b/MoreLinq/Fold.cs
@@ -1,64 +1,64 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- static TResult FoldImpl(IEnumerable source, int count,
- Func folder1,
- Func folder2,
- Func folder3,
- Func folder4)
- {
- if (source == null) throw new ArgumentNullException("source");
- if ( count == 1 && folder1 == null
- || count == 2 && folder2 == null
- || count == 3 && folder3 == null
- || count == 4 && folder4 == null)
- { // ReSharper disable NotResolvedInText
- throw new ArgumentNullException("folder"); // ReSharper restore NotResolvedInText
- }
-
- var elements = new T[count];
- foreach (var e in AssertCountImpl(source.Index(), count, OnFolderSourceSizeErrorSelector))
- elements[e.Key] = e.Value;
-
- switch (count)
- {
- case 1: return folder1(elements[0]);
- case 2: return folder2(elements[0], elements[1]);
- case 3: return folder3(elements[0], elements[1], elements[2]);
- case 4: return folder4(elements[0], elements[1], elements[2], elements[3]);
- default: throw new NotSupportedException();
- }
- }
-
- static readonly Func OnFolderSourceSizeErrorSelector = OnFolderSourceSizeError;
-
- static Exception OnFolderSourceSizeError(int cmp, int count)
- {
- var message = cmp < 0
- ? "Sequence contains too few elements when exactly {0} {1} expected."
- : "Sequence contains too many elements when exactly {0} {1} expected.";
- return new Exception(string.Format(message, count.ToString("N0"), count == 1 ? "was" : "were"));
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ static TResult FoldImpl(IEnumerable source, int count,
+ Func folder1,
+ Func folder2,
+ Func folder3,
+ Func folder4)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ if ( count == 1 && folder1 == null
+ || count == 2 && folder2 == null
+ || count == 3 && folder3 == null
+ || count == 4 && folder4 == null)
+ { // ReSharper disable NotResolvedInText
+ throw new ArgumentNullException("folder"); // ReSharper restore NotResolvedInText
+ }
+
+ var elements = new T[count];
+ foreach (var e in AssertCountImpl(source.Index(), count, OnFolderSourceSizeErrorSelector))
+ elements[e.Key] = e.Value;
+
+ switch (count)
+ {
+ case 1: return folder1(elements[0]);
+ case 2: return folder2(elements[0], elements[1]);
+ case 3: return folder3(elements[0], elements[1], elements[2]);
+ case 4: return folder4(elements[0], elements[1], elements[2], elements[3]);
+ default: throw new NotSupportedException();
+ }
+ }
+
+ static readonly Func OnFolderSourceSizeErrorSelector = OnFolderSourceSizeError;
+
+ static Exception OnFolderSourceSizeError(int cmp, int count)
+ {
+ var message = cmp < 0
+ ? "Sequence contains too few elements when exactly {0} {1} expected."
+ : "Sequence contains too many elements when exactly {0} {1} expected.";
+ return new Exception(string.Format(message, count.ToString("N0"), count == 1 ? "was" : "were"));
+ }
+ }
+}
diff --git a/MoreLinq/Fold.g.cs b/MoreLinq/Fold.g.cs
index 7f3ce48b8..19b81cb5b 100644
--- a/MoreLinq/Fold.g.cs
+++ b/MoreLinq/Fold.g.cs
@@ -1,98 +1,98 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- partial class MoreEnumerable
- {
- ///
- /// Returns the result of applying a function to a sequence of
- /// 1 element.
- ///
- ///
- /// This operator uses immediate execution and effectively buffers
- /// as many items of the source sequence as necessary.
- ///
- /// Type of element in the source sequence
- /// Type of the result
- /// The sequence of items to fold.
- /// Function to apply to the elements in the sequence.
-
- public static TResult Fold(this IEnumerable source, Func folder)
- {
- return FoldImpl(source, 1, folder, null, null, null);
- }
-
- ///
- /// Returns the result of applying a function to a sequence of
- /// 2 elements.
- ///
- ///
- /// This operator uses immediate execution and effectively buffers
- /// as many items of the source sequence as necessary.
- ///
- /// Type of element in the source sequence
- /// Type of the result
- /// The sequence of items to fold.
- /// Function to apply to the elements in the sequence.
-
- public static TResult Fold(this IEnumerable source, Func folder)
- {
- return FoldImpl(source, 2, null, folder, null, null);
- }
-
- ///
- /// Returns the result of applying a function to a sequence of
- /// 3 elements.
- ///
- ///
- /// This operator uses immediate execution and effectively buffers
- /// as many items of the source sequence as necessary.
- ///
- /// Type of element in the source sequence
- /// Type of the result
- /// The sequence of items to fold.
- /// Function to apply to the elements in the sequence.
-
- public static TResult Fold(this IEnumerable source, Func folder)
- {
- return FoldImpl(source, 3, null, null, folder, null);
- }
-
- ///
- /// Returns the result of applying a function to a sequence of
- /// 4 elements.
- ///
- ///
- /// This operator uses immediate execution and effectively buffers
- /// as many items of the source sequence as necessary.
- ///
- /// Type of element in the source sequence
- /// Type of the result
- /// The sequence of items to fold.
- /// Function to apply to the elements in the sequence.
-
- public static TResult Fold(this IEnumerable source, Func folder)
- {
- return FoldImpl(source, 4, null, null, null, folder);
- }
-
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ partial class MoreEnumerable
+ {
+ ///
+ /// Returns the result of applying a function to a sequence of
+ /// 1 element.
+ ///
+ ///
+ /// This operator uses immediate execution and effectively buffers
+ /// as many items of the source sequence as necessary.
+ ///
+ /// Type of element in the source sequence
+ /// Type of the result
+ /// The sequence of items to fold.
+ /// Function to apply to the elements in the sequence.
+
+ public static TResult Fold(this IEnumerable source, Func folder)
+ {
+ return FoldImpl(source, 1, folder, null, null, null);
+ }
+
+ ///
+ /// Returns the result of applying a function to a sequence of
+ /// 2 elements.
+ ///
+ ///
+ /// This operator uses immediate execution and effectively buffers
+ /// as many items of the source sequence as necessary.
+ ///
+ /// Type of element in the source sequence
+ /// Type of the result
+ /// The sequence of items to fold.
+ /// Function to apply to the elements in the sequence.
+
+ public static TResult Fold(this IEnumerable source, Func folder)
+ {
+ return FoldImpl(source, 2, null, folder, null, null);
+ }
+
+ ///
+ /// Returns the result of applying a function to a sequence of
+ /// 3 elements.
+ ///
+ ///
+ /// This operator uses immediate execution and effectively buffers
+ /// as many items of the source sequence as necessary.
+ ///
+ /// Type of element in the source sequence
+ /// Type of the result
+ /// The sequence of items to fold.
+ /// Function to apply to the elements in the sequence.
+
+ public static TResult Fold(this IEnumerable source, Func folder)
+ {
+ return FoldImpl(source, 3, null, null, folder, null);
+ }
+
+ ///
+ /// Returns the result of applying a function to a sequence of
+ /// 4 elements.
+ ///
+ ///
+ /// This operator uses immediate execution and effectively buffers
+ /// as many items of the source sequence as necessary.
+ ///
+ /// Type of element in the source sequence
+ /// Type of the result
+ /// The sequence of items to fold.
+ /// Function to apply to the elements in the sequence.
+
+ public static TResult Fold(this IEnumerable source, Func folder)
+ {
+ return FoldImpl(source, 4, null, null, null, folder);
+ }
+
+ }
+}
diff --git a/MoreLinq/Fold.g.tt b/MoreLinq/Fold.g.tt
index b17f26769..40dc2440d 100644
--- a/MoreLinq/Fold.g.tt
+++ b/MoreLinq/Fold.g.tt
@@ -1,67 +1,67 @@
-<#@ template debug="false" hostspecific="false" language="C#" #>
-<#@ output extension=".cs" #>
-<#@ assembly name="System.Core" #>
-<#@ import namespace="System.Globalization" #>
-<#@ import namespace="System.Linq" #>
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- partial class MoreEnumerable
- {
-<# const int max = 4;
- var overloads =
- from i in Enumerable.Range(1, max)
- let istr = i.ToString(CultureInfo.InvariantCulture)
- select new
- {
- Ts = string.Join(", ", Enumerable.Repeat("T", i)),
- Count = i,
- CountElements = istr + " " + (i == 1 ? "element" : "elements"),
- CountArg = istr,
- FolderArgs = string.Join(", ", Enumerable.Repeat("null", i - 1)
- .Concat(new[] { "folder" })
- .Concat(Enumerable.Repeat("null", max - i))),
-
- };
-
- foreach (var e in overloads) { #>
- ///
- /// Returns the result of applying a function to a sequence of
- /// <#= e.CountElements #>.
- ///
- ///
- /// This operator uses immediate execution and effectively buffers
- /// as many items of the source sequence as necessary.
- ///
- /// Type of element in the source sequence
- /// Type of the result
- /// The sequence of items to fold.
- /// Function to apply to the elements in the sequence.
-
- public static TResult Fold(this IEnumerable source, Func<<#= e.Ts #>, TResult> folder)
- {
- return FoldImpl(source, <#= e.CountArg #>, <#= e.FolderArgs #>);
- }
-
-<# } #>
- }
-}
+<#@ template debug="false" hostspecific="false" language="C#" #>
+<#@ output extension=".cs" #>
+<#@ assembly name="System.Core" #>
+<#@ import namespace="System.Globalization" #>
+<#@ import namespace="System.Linq" #>
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ partial class MoreEnumerable
+ {
+<# const int max = 4;
+ var overloads =
+ from i in Enumerable.Range(1, max)
+ let istr = i.ToString(CultureInfo.InvariantCulture)
+ select new
+ {
+ Ts = string.Join(", ", Enumerable.Repeat("T", i)),
+ Count = i,
+ CountElements = istr + " " + (i == 1 ? "element" : "elements"),
+ CountArg = istr,
+ FolderArgs = string.Join(", ", Enumerable.Repeat("null", i - 1)
+ .Concat(new[] { "folder" })
+ .Concat(Enumerable.Repeat("null", max - i))),
+
+ };
+
+ foreach (var e in overloads) { #>
+ ///
+ /// Returns the result of applying a function to a sequence of
+ /// <#= e.CountElements #>.
+ ///
+ ///
+ /// This operator uses immediate execution and effectively buffers
+ /// as many items of the source sequence as necessary.
+ ///
+ /// Type of element in the source sequence
+ /// Type of the result
+ /// The sequence of items to fold.
+ /// Function to apply to the elements in the sequence.
+
+ public static TResult Fold(this IEnumerable source, Func<<#= e.Ts #>, TResult> folder)
+ {
+ return FoldImpl(source, <#= e.CountArg #>, <#= e.FolderArgs #>);
+ }
+
+<# } #>
+ }
+}
diff --git a/MoreLinq/ForEach.cs b/MoreLinq/ForEach.cs
index c0893a162..b45ce79d6 100644
--- a/MoreLinq/ForEach.cs
+++ b/MoreLinq/ForEach.cs
@@ -1,42 +1,42 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Immediately executes the given action on each element in the source sequence.
- ///
- /// The type of the elements in the sequence
- /// The sequence of elements
- /// The action to execute on each element
-
- public static void ForEach(this IEnumerable source, Action action)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (action == null) throw new ArgumentNullException("action");
- foreach (var element in source)
- {
- action(element);
- }
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Immediately executes the given action on each element in the source sequence.
+ ///
+ /// The type of the elements in the sequence
+ /// The sequence of elements
+ /// The action to execute on each element
+
+ public static void ForEach(this IEnumerable source, Action action)
+ {
+ if (source == null) throw new ArgumentNullException("source");
+ if (action == null) throw new ArgumentNullException("action");
+ foreach (var element in source)
+ {
+ action(element);
+ }
+ }
+ }
+}
diff --git a/MoreLinq/Generate.cs b/MoreLinq/Generate.cs
index ec0a67624..444fec6a7 100644
--- a/MoreLinq/Generate.cs
+++ b/MoreLinq/Generate.cs
@@ -1,59 +1,59 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Returns a sequence of values consecutively generated by a generator function.
- ///
- /// Type of elements to generate.
- /// Value of first element in sequence
- ///
- /// Generator function which takes the previous series element and uses it to generate the next element.
- ///
- ///
- /// This function defers element generation until needed and streams the results.
- ///
- ///
- ///
- /// IEnumerable<int> result = Sequence.Generate(2, n => n * n).Take(5);
- ///
- /// The result variable, when iterated over, will yield 2, 4, 16, 256, and 65536, in turn.
- ///
-
- public static IEnumerable Generate(TResult initial, Func generator)
- {
- if (generator == null) throw new ArgumentNullException("generator");
- return GenerateImpl(initial, generator);
- }
-
- private static IEnumerable GenerateImpl(TResult initial, Func generator)
- {
- var current = initial;
- while (true)
- {
- yield return current;
- current = generator(current);
- }
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Returns a sequence of values consecutively generated by a generator function.
+ ///
+ /// Type of elements to generate.
+ /// Value of first element in sequence
+ ///
+ /// Generator function which takes the previous series element and uses it to generate the next element.
+ ///
+ ///
+ /// This function defers element generation until needed and streams the results.
+ ///
+ ///
+ ///
+ /// IEnumerable<int> result = Sequence.Generate(2, n => n * n).Take(5);
+ ///
+ /// The result variable, when iterated over, will yield 2, 4, 16, 256, and 65536, in turn.
+ ///
+
+ public static IEnumerable Generate(TResult initial, Func generator)
+ {
+ if (generator == null) throw new ArgumentNullException("generator");
+ return GenerateImpl(initial, generator);
+ }
+
+ private static IEnumerable GenerateImpl(TResult initial, Func generator)
+ {
+ var current = initial;
+ while (true)
+ {
+ yield return current;
+ current = generator(current);
+ }
+ }
+ }
+}
diff --git a/MoreLinq/GenerateByIndex.cs b/MoreLinq/GenerateByIndex.cs
index 13988d8fc..06abf14a0 100644
--- a/MoreLinq/GenerateByIndex.cs
+++ b/MoreLinq/GenerateByIndex.cs
@@ -1,56 +1,56 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections.Generic;
-
- static partial class MoreEnumerable
- {
- ///
- /// Returns a sequence of values based on indexes.
- ///
- ///
- /// The sequence is (practically) infinite
- /// - the index ranges from 0 to int.MaxValue inclusive. This function defers
- /// execution and streams the results.
- ///
- /// Type of result to generate
- /// Generation function to apply to each index
- /// A sequence
-
- public static IEnumerable GenerateByIndex(Func generator)
- {
- // Would just use Enumerable.Range(0, int.MaxValue).Select(generator) but that doesn't
- // include int.MaxValue. Picky, I know...
- if (generator == null) throw new ArgumentNullException("generator");
- return GenerateByIndexImpl(generator);
- }
-
- private static IEnumerable GenerateByIndexImpl(Func generator)
- {
- // Looping over 0...int.MaxValue inclusive is a pain. Simplest is to go exclusive,
- // then go again for int.MaxValue.
- for (var i = 0; i < int.MaxValue; i++)
- {
- yield return generator(i);
- }
- yield return generator(int.MaxValue);
- }
- }
-}
+#region License and Terms
+// MoreLINQ - Extensions to LINQ to Objects
+// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#endregion
+
+namespace MoreLinq
+{
+ using System;
+ using System.Collections.Generic;
+
+ static partial class MoreEnumerable
+ {
+ ///
+ /// Returns a sequence of values based on indexes.
+ ///
+ ///
+ /// The sequence is (practically) infinite
+ /// - the index ranges from 0 to int.MaxValue inclusive. This function defers
+ /// execution and streams the results.
+ ///
+ /// Type of result to generate
+ /// Generation function to apply to each index
+ /// A sequence
+
+ public static IEnumerable GenerateByIndex(Func generator)
+ {
+ // Would just use Enumerable.Range(0, int.MaxValue).Select(generator) but that doesn't
+ // include int.MaxValue. Picky, I know...
+ if (generator == null) throw new ArgumentNullException("generator");
+ return GenerateByIndexImpl(generator);
+ }
+
+ private static IEnumerable GenerateByIndexImpl(Func generator)
+ {
+ // Looping over 0...int.MaxValue inclusive is a pain. Simplest is to go exclusive,
+ // then go again for int.MaxValue.
+ for (var i = 0; i < int.MaxValue; i++)
+ {
+ yield return generator(i);
+ }
+ yield return generator(int.MaxValue);
+ }
+ }
+}
diff --git a/MoreLinq/GroupAdjacent.cs b/MoreLinq/GroupAdjacent.cs
index 3f42716e7..29f0d6307 100644
--- a/MoreLinq/GroupAdjacent.cs
+++ b/MoreLinq/GroupAdjacent.cs
@@ -1,252 +1,252 @@
-#region License and Terms
-// MoreLINQ - Extensions to LINQ to Objects
-// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#endregion
-
-namespace MoreLinq
-{
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Linq;
-
- static partial class MoreEnumerable
- {
- ///
- /// Groups the adjacent elements of a sequence according to a
- /// specified key selector function.
- ///
- /// The type of the elements of
- /// .
- /// The type of the key returned by
- /// .
- /// A sequence whose elements to group.
- /// A function to extract the key for each
- /// element.
- /// A sequence of groupings where each grouping
- /// () contains the key
- /// and the adjacent elements in the same order as found in the
- /// source sequence.
- ///
- /// This method is implemented by using deferred execution and
- /// streams the groupings. The grouping elements, however, are
- /// buffered. Each grouping is therefore yielded as soon as it
- /// is complete and before the next grouping occurs.
- ///
-
- public static IEnumerable> GroupAdjacent(
- this IEnumerable source,
- Func keySelector)
- {
- return GroupAdjacent(source, keySelector, null);
- }
-
- ///
- /// Groups the adjacent elements of a sequence according to a
- /// specified key selector function and compares the keys by using a
- /// specified comparer.
- ///
- /// The type of the elements of
- /// .
- /// The type of the key returned by
- /// .
- /// A sequence whose elements to group.
- /// A function to extract the key for each
- /// element.
- /// An to
- /// compare keys.
- /// A sequence of groupings where each grouping
- /// () contains the key
- /// and the adjacent elements in the same order as found in the
- /// source sequence.
- ///
- /// This method is implemented by using deferred execution and
- /// streams the groupings. The grouping elements, however, are
- /// buffered. Each grouping is therefore yielded as soon as it
- /// is complete and before the next grouping occurs.
- ///
-
- public static IEnumerable> GroupAdjacent(
- this IEnumerable source,
- Func keySelector,
- IEqualityComparer comparer)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (keySelector == null) throw new ArgumentNullException("keySelector");
-
- return GroupAdjacent(source, keySelector, e => e, comparer);
- }
-
- ///
- /// Groups the adjacent elements of a sequence according to a
- /// specified key selector function and projects the elements for
- /// each group by using a specified function.
- ///
- /// The type of the elements of
- /// .
- /// The type of the key returned by
- /// .
- /// The type of the elements in the
- /// resulting groupings.
- /// A sequence whose elements to group.
- /// A function to extract the key for each
- /// element.
- /// A function to map each source
- /// element to an element in the resulting grouping.
- /// A sequence of groupings where each grouping
- /// () contains the key
- /// and the adjacent elements (of type )
- /// in the same order as found in the source sequence.
- ///
- /// This method is implemented by using deferred execution and
- /// streams the groupings. The grouping elements, however, are
- /// buffered. Each grouping is therefore yielded as soon as it
- /// is complete and before the next grouping occurs.
- ///
-
- public static IEnumerable> GroupAdjacent(
- this IEnumerable source,
- Func keySelector,
- Func elementSelector)
- {
- return GroupAdjacent(source, keySelector, elementSelector, null);
- }
-
- ///
- /// Groups the adjacent elements of a sequence according to a
- /// specified key selector function. The keys are compared by using
- /// a comparer and each group's elements are projected by using a
- /// specified function.
- ///
- /// The type of the elements of
- /// .
- /// The type of the key returned by
- /// .
- /// The type of the elements in the
- /// resulting groupings.
- /// A sequence whose elements to group.
- /// A function to extract the key for each
- /// element.
- /// A function to map each source
- /// element to an element in the resulting grouping.
- /// An to
- /// compare keys.
- /// A sequence of groupings where each grouping
- /// () contains the key
- /// and the adjacent elements (of type )
- /// in the same order as found in the source sequence.
- ///
- /// This method is implemented by using deferred execution and
- /// streams the groupings. The grouping elements, however, are
- /// buffered. Each grouping is therefore yielded as soon as it
- /// is complete and before the next grouping occurs.
- ///
-
- public static IEnumerable> GroupAdjacent(
- this IEnumerable