Skip to content

Commit

Permalink
Renaming Zip to ZipShortest (Fixes issue #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Jun 22, 2013
1 parent 389277e commit 88c573f
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 41 deletions.
2 changes: 1 addition & 1 deletion MoreLinq.Test/AcquireTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void AcquireAll()

Assert.That(disposables.Length, Is.EqualTo(3));

foreach (var disposable in disposables.Zip(new[] { a, b, c }, (act, exp) => new { Actual = act, Expected = exp }))
foreach (var disposable in disposables.ZipShortest(new[] { a, b, c }, (act, exp) => new { Actual = act, Expected = exp }))
{
Assert.That(disposable.Actual, Is.SameAs(disposable.Expected));
Assert.That(disposable.Actual.Disposed, Is.False);
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/MoreLinq.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<Compile Include="ForEachTest.cs" />
<Compile Include="DistinctByTest.cs" />
<Compile Include="GenerateTest.cs" />
<Compile Include="ZipTest.cs" />
<Compile Include="ZipShortestTest.cs" />
<Compile Include="PrependTest.cs" />
<Compile Include="PadTest.cs" />
<Compile Include="CurrentThreadCultureScope.cs" />
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/ScanTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void ScanEmpty()
public void ScanSum()
{
var result = SampleData.Values.Scan(SampleData.Plus);
var gold = SampleData.Values.PreScan(SampleData.Plus, 0).Zip(SampleData.Values, SampleData.Plus);
var gold = SampleData.Values.PreScan(SampleData.Plus, 0).ZipShortest(SampleData.Values, SampleData.Plus);
result.AssertSequenceEqual(gold);
}
}
Expand Down
34 changes: 17 additions & 17 deletions MoreLinq.Test/ZipTest.cs → MoreLinq.Test/ZipShortestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace MoreLinq.Test
{
[TestFixture]
public class ZipTest
public class ZipShortestTest
{
private static Tuple<TFirst, TSecond> Tuple<TFirst, TSecond>(TFirst a, TSecond b)
{
Expand All @@ -34,7 +34,7 @@ public void BothSequencesDisposedWithUnequalLengthsAndLongerFirst()
using (var longer = TestingSequence.Of(1, 2, 3))
using (var shorter = TestingSequence.Of(1, 2))
{
longer.Zip(shorter, (x, y) => x + y).Consume();
longer.ZipShortest(shorter, (x, y) => x + y).Consume();
}
}

Expand All @@ -44,60 +44,60 @@ public void BothSequencesDisposedWithUnequalLengthsAndShorterFirst()
using (var longer = TestingSequence.Of(1, 2, 3))
using (var shorter = TestingSequence.Of(1, 2))
{
shorter.Zip(longer, (x, y) => x + y).Consume();
shorter.ZipShortest(longer, (x, y) => x + y).Consume();
}
}

[Test]
public void ZipWithEqualLengthSequences()
public void ZipShortestWithEqualLengthSequences()
{
var zipped = new[] { 1, 2, 3 }.Zip(new[] { 4, 5, 6 }, Tuple);
var zipped = new[] { 1, 2, 3 }.ZipShortest(new[] { 4, 5, 6 }, Tuple);
Assert.That(zipped, Is.Not.Null);
zipped.AssertSequenceEqual(Tuple(1, 4), Tuple(2, 5), Tuple(3, 6));
}

[Test]
public void ZipWithFirstSequenceShorterThanSecond()
public void ZipShortestWithFirstSequenceShorterThanSecond()
{
var zipped = new[] { 1, 2 }.Zip(new[] { 4, 5, 6 }, Tuple);
var zipped = new[] { 1, 2 }.ZipShortest(new[] { 4, 5, 6 }, Tuple);
Assert.That(zipped, Is.Not.Null);
zipped.AssertSequenceEqual(Tuple(1, 4), Tuple(2, 5));
}

[Test]
public void ZipWithFirstSequnceLongerThanSecond()
public void ZipShortestWithFirstSequnceLongerThanSecond()
{
var zipped = new[] { 1, 2, 3 }.Zip(new[] { 4, 5 }, Tuple);
var zipped = new[] { 1, 2, 3 }.ZipShortest(new[] { 4, 5 }, Tuple);
Assert.That(zipped, Is.Not.Null);
zipped.AssertSequenceEqual(Tuple(1, 4), Tuple(2, 5));
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ZipWithNullFirstSequence()
public void ZipShortestWithNullFirstSequence()
{
MoreEnumerable.Zip(null, new[] { 4, 5, 6 }, BreakingFunc.Of<int, int, int>());
MoreEnumerable.ZipShortest(null, new[] { 4, 5, 6 }, BreakingFunc.Of<int, int, int>());
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ZipWithNullSecondSequence()
public void ZipShortestWithNullSecondSequence()
{
new[] { 1, 2, 3 }.Zip(null, BreakingFunc.Of<int, int, int>());
new[] { 1, 2, 3 }.ZipShortest(null, BreakingFunc.Of<int, int, int>());
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ZipWithNullResultSelector()
public void ZipShortestWithNullResultSelector()
{
new[] { 1, 2, 3 }.Zip<int, int, int>(new[] { 4, 5, 6 }, null);
new[] { 1, 2, 3 }.ZipShortest<int, int, int>(new[] { 4, 5, 6 }, null);
}

[Test]
public void ZipIsLazy()
public void ZipShortestIsLazy()
{
var bs = new BreakingSequence<int>();
bs.Zip<int, int, int>(bs, delegate { throw new NotImplementedException(); });
bs.ZipShortest<int, int, int>(bs, delegate { throw new NotImplementedException(); });
}
}
}
2 changes: 1 addition & 1 deletion MoreLinq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuspecs", "Nuspecs", "{55D0
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.ZipShortest.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ZipShortest.nuspec
pkg\MoreLinq.Source.MoreEnumerable.ZipLongest.nuspec = pkg\MoreLinq.Source.MoreEnumerable.ZipLongest.nuspec
EndProjectSection
EndProject
Expand Down
5 changes: 1 addition & 4 deletions MoreLinq/MoreLinq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@
<Compile Include="TakeEvery.cs">
<DependentUpon>MoreEnumerable.cs</DependentUpon>
</Compile>
<Compile Include="Zip.cs">
<DependentUpon>MoreEnumerable.cs</DependentUpon>
</Compile>
<Compile Include="Zip.stub.cs">
<Compile Include="ZipShortest.cs">
<DependentUpon>MoreEnumerable.cs</DependentUpon>
</Compile>
<Compile Include="EquiZip.cs">
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Partition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static IEnumerable<IEnumerable<TSource>> Partition<TSource>(this IEnumera
var collectorFilled = false;

// Zip shortest
foreach (var itemInstructionPair in source.Zip(splitInstructions, (x, y) => new { Item = x, Instruction = y }))
foreach (var itemInstructionPair in source.ZipShortest(splitInstructions, (x, y) => new { Item = x, Instruction = y }))
{
switch (itemInstructionPair.Instruction)
{
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/PreScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static partial class MoreEnumerable
/// int[] values = { 1, 2, 3, 4 };
/// IEnumerable&lt;int&gt; prescan = values.PreScan(plus, 0);
/// IEnumerable&lt;int&gt; scan = values.Scan(plus; a + b);
/// IEnumerable&lt;int&gt; result = values.Zip(prescan, plus);
/// IEnumerable&lt;int&gt; result = values.ZipShortest(prescan, plus);
/// </code>
/// <c>prescan</c> will yield <c>{ 0, 1, 3, 6 }</c>, while <c>scan</c>
/// and <c>result</c> will both yield <c>{ 1, 3, 6, 10 }</c>. This
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static partial class MoreEnumerable
/// int[] values = { 1, 2, 3, 4 };
/// IEnumerable&lt;int&gt; prescan = values.PreScan(plus, 0);
/// IEnumerable&lt;int&gt; scan = values.Scan(plus; a + b);
/// IEnumerable&lt;int&gt; result = values.Zip(prescan, plus);
/// IEnumerable&lt;int&gt; result = values.ZipShortest(prescan, plus);
/// </code>
/// <c>prescan</c> will yield <c>{ 0, 1, 3, 6 }</c>, while <c>scan</c>
/// and <c>result</c> will both yield <c>{ 1, 3, 6, 10 }</c>. This
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq/Zip.cs → MoreLinq/ZipShortest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static partial class MoreEnumerable
/// <code>
/// int[] numbers = { 1, 2, 3 };
/// string[] letters = { "A", "B", "C", "D" };
/// var zipped = numbers.Zip(letters, (n, l) => n + l);
/// var zipped = numbers.ZipShortest(letters, (n, l) => n + l);
/// </code>
/// The <c>zipped</c> variable, when iterated over, will yield "1A", "2B", "3C", in turn.
/// </example>
Expand All @@ -46,7 +46,7 @@ static partial class MoreEnumerable
/// <param name="second">Second sequence</param>
/// <param name="resultSelector">Function to apply to each pair of elements</param>

public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first,
public static IEnumerable<TResult> ZipShortest<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first,
IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException("first");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>MoreLinq.Source.MoreEnumerable.Zip</id>
<version>1.0.1</version>
<title>MoreLINQ's Zip for C# Sequences (Source)</title>
<id>MoreLinq.Source.MoreEnumerable.ZipShortest</id>
<version>1.0.0</version>
<title>MoreLINQ's ZipShortest for C# Sequences (Source)</title>
<authors>MoreLINQ Developers</authors>
<owners>Jon Skeet, Atif Aziz</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<projectUrl>http://code.google.com/p/morelinq/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>Enhances LINQ to Objects with the method Zip (2 overloads)</summary>
<description>C# source implementation that enhances LINQ to Objects with the method Zip. Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences.</description>
<description>C# source implementation that enhances LINQ to Objects with the method ZipShortest. Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences.</description>
<language>en-US</language>
<tags>linq extensions</tags>
<releaseNotes>Microsoft .NET Framework 2.0 support via LINQBridge</releaseNotes>
Expand All @@ -22,7 +22,6 @@
</dependencies>
</metadata>
<files>
<file src="..\MoreLinq\Zip.cs" target="content\net20\MoreLinq\MoreEnumerable.Zip.cs" />
<file src="..\MoreLinq\Zip.stub.cs" target="content\net40\MoreLinq\MoreEnumerable.Zip.cs" />
<file src="..\MoreLinq\ZipShortest.cs" target="content\net20\MoreLinq\MoreEnumerable.ZipShortest.cs" />
</files>
</package>
8 changes: 4 additions & 4 deletions pkg/MoreLinq.Source.MoreEnumerable.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package>
<metadata>
<id>MoreLinq.Source.MoreEnumerable</id>
<version>1.1.1</version>
<version>2.0.0</version>
<title>MoreLINQ for C# Sequences (Source)</title>
<authors>MoreLINQ Developers</authors>
<owners>Jon Skeet, Atif Aziz</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<projectUrl>http://code.google.com/p/morelinq/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>Enhances LINQ to Objects with extra methods, in a manner which keeps to the spirit of LINQ.</summary>
<description>C# source implementation that enhances LINQ to Objects with the following methods: Acquire, AssertCount, Batch, Concat, Consume, DistinctBy, EquiZip, ExceptBy, Fold, ForEach, Generate, GenerateByIndex, GroupAdjacent, Index, MaxBy, MinBy, Pad, Pairwise, Pipe, Prepend, PreScan, Scan, SingleOrFallback, SkipUntil, Split, TakeEvery, TakeLast, TakeUntil, ToDataTable, ToDelimitedString, ToHashSet, Trace, Zip, ZipLongest</description>
<description>C# source implementation that enhances LINQ to Objects with the following methods: Acquire, AssertCount, Batch, Concat, Consume, DistinctBy, EquiZip, ExceptBy, Fold, ForEach, Generate, GenerateByIndex, GroupAdjacent, Index, MaxBy, MinBy, Pad, Pairwise, Pipe, Prepend, PreScan, Scan, SingleOrFallback, SkipUntil, Split, TakeEvery, TakeLast, TakeUntil, ToDataTable, ToDelimitedString, ToHashSet, Trace, ZipLongest, ZipShortest</description>
<language>en-US</language>
<tags>linq extensions</tags>
<releaseNotes>Microsoft .NET Framework 2.0 support via LINQBridge</releaseNotes>
Expand Down Expand Up @@ -48,8 +48,8 @@
<dependency id="MoreLinq.Source.MoreEnumerable.ToDelimitedString" version="[1.1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.ToHashSet" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.Trace" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.Zip" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.ZipLongest" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.ZipShortest" version="[1,2)" />
</group>
<group targetFramework="net20">
<dependency id="MoreLinq.Source.MoreEnumerable.Acquire" version="[1,2)" />
Expand Down Expand Up @@ -88,8 +88,8 @@
<!-- Excluded as HashSet<T> is not available in .NET 2.0
<dependency id="MoreLinq.Source.MoreEnumerable.ToHashSet" version="[1,2)" />-->
<dependency id="MoreLinq.Source.MoreEnumerable.Trace" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.Zip" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.ZipLongest" version="[1,2)" />
<dependency id="MoreLinq.Source.MoreEnumerable.ZipShortest" version="[1,2)" />
</group>
</dependencies>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion pkg/morelinq.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<projectUrl>http://code.google.com/p/morelinq/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>This project enhances LINQ to Objects with extra methods, in a manner which keeps to the spirit of LINQ.</summary>
<description>This project enhances LINQ to Objects with the following methods: Acquire, AssertCount, Batch, Concat, Consume, DistinctBy, EquiZip, ExceptBy, Fold, ForEach, Generate, GenerateByIndex, GroupAdjacent, Index, MaxBy, MinBy, Pad, Pairwise, Pipe, Prepend, PreScan, Scan, SingleOrFallback, SkipUntil, Split, TakeEvery, TakeLast, TakeUntil, ToDataTable, ToDelimitedString, ToHashSet, Trace, Zip, ZipLongest</description>
<description>This project enhances LINQ to Objects with the following methods: Acquire, AssertCount, Batch, Concat, Consume, DistinctBy, EquiZip, ExceptBy, Fold, ForEach, Generate, GenerateByIndex, GroupAdjacent, Index, MaxBy, MinBy, Pad, Pairwise, Pipe, Prepend, PreScan, Scan, SingleOrFallback, SkipUntil, Split, TakeEvery, TakeLast, TakeUntil, ToDataTable, ToDelimitedString, ToHashSet, Trace, ZipLongest, ZipShortest</description>
<language>en-US</language>
<tags>linq extensions</tags>
<releaseNotes>See http://code.google.com/p/morelinq/wiki/ApiChanges</releaseNotes>
Expand Down

0 comments on commit 88c573f

Please sign in to comment.