-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert removal of "Append" and "Prepend"
This reverts commits: - Remove unused "Append"/"Prepend"supporting types: b9316f7 - Remove "Append" and "Prepend": ca3a8e2
- Loading branch information
Showing
11 changed files
with
534 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#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 !NET471_OR_GREATER && !NETSTANDARD1_6_OR_GREATER && !NETCOREAPP2_0_OR_GREATER | ||
|
||
namespace MoreLinq.Test | ||
{ | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class AppendTest | ||
{ | ||
#region Append with single head and tail sequence | ||
[Test] | ||
public void AppendWithNonEmptyHeadSequence() | ||
{ | ||
var head = new[] { "first", "second" }; | ||
var tail = "third"; | ||
var whole = head.Append(tail); | ||
whole.AssertSequenceEqual("first", "second", "third"); | ||
} | ||
|
||
[Test] | ||
public void AppendWithEmptyHeadSequence() | ||
{ | ||
string[] head = { }; | ||
var tail = "first"; | ||
var whole = head.Append(tail); | ||
whole.AssertSequenceEqual("first"); | ||
} | ||
|
||
[Test] | ||
public void AppendWithNullTail() | ||
{ | ||
var head = new[] { "first", "second" }; | ||
string? tail = null; | ||
var whole = head.Append(tail); | ||
whole.AssertSequenceEqual("first", "second", null); | ||
} | ||
|
||
[Test] | ||
public void AppendIsLazyInHeadSequence() | ||
{ | ||
_ = new BreakingSequence<string>().Append("tail"); | ||
} | ||
#endregion | ||
|
||
[TestCaseSource(nameof(ContactManySource))] | ||
public void AppendMany(int[] head, int[] tail) | ||
{ | ||
tail.Aggregate(head.AsEnumerable(), (xs, x) => xs.Append(x)) | ||
.AssertSequenceEqual(head.Concat(tail)); | ||
} | ||
|
||
public static IEnumerable<object> ContactManySource => | ||
from x in Enumerable.Range(0, 11) | ||
from y in Enumerable.Range(1, 20 - x) | ||
select new | ||
{ | ||
Head = Enumerable.Range(1, x).ToArray(), | ||
Tail = Enumerable.Range(x + 1, y).ToArray(), | ||
} | ||
into e | ||
select new TestCaseData(e.Head, | ||
e.Tail).SetName("Head = [" + string.Join(", ", e.Head) + "], " + | ||
"Tail = [" + string.Join(", ", e.Tail) + "]"); | ||
|
||
[Test] | ||
public void AppendWithSharedSource() | ||
{ | ||
var first = new[] { 1 }.Append(2); | ||
var second = first.Append(3).Append(4); | ||
var third = first.Append(4).Append(8); | ||
|
||
second.AssertSequenceEqual(1, 2, 3, 4); | ||
third.AssertSequenceEqual(1, 2, 4, 8); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#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 !NET471_OR_GREATER && !NETSTANDARD1_6_OR_GREATER && !NETCOREAPP2_0_OR_GREATER | ||
|
||
namespace MoreLinq.Test | ||
{ | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Interfaces; | ||
|
||
[TestFixture] | ||
public class PrependTest | ||
{ | ||
[Test] | ||
public void PrependWithNonEmptyTailSequence() | ||
{ | ||
string[] tail = { "second", "third" }; | ||
var head = "first"; | ||
var whole = tail.Prepend(head); | ||
whole.AssertSequenceEqual("first", "second", "third"); | ||
} | ||
|
||
[Test] | ||
public void PrependWithEmptyTailSequence() | ||
{ | ||
string[] tail = { }; | ||
var head = "first"; | ||
var whole = tail.Prepend(head); | ||
whole.AssertSequenceEqual("first"); | ||
} | ||
|
||
[Test] | ||
public void PrependWithNullHead() | ||
{ | ||
string[] tail = { "second", "third" }; | ||
string? head = null; | ||
var whole = tail.Prepend(head); | ||
whole.AssertSequenceEqual(null, "second", "third"); | ||
} | ||
|
||
[Test] | ||
public void PrependIsLazyInTailSequence() | ||
{ | ||
_ = new BreakingSequence<string>().Prepend("head"); | ||
} | ||
|
||
[TestCaseSource(nameof(PrependManySource))] | ||
public int[] PrependMany(int[] head, int[] tail) | ||
{ | ||
return tail.Aggregate(head.AsEnumerable(), MoreEnumerable.Prepend).ToArray(); | ||
} | ||
|
||
public static IEnumerable<ITestCaseData> PrependManySource => | ||
from x in Enumerable.Range(0, 11) | ||
from y in Enumerable.Range(1, 11) | ||
select new | ||
{ | ||
Head = Enumerable.Range(0, y).Select(n => 0 - n).ToArray(), | ||
Tail = Enumerable.Range(1, x).ToArray(), | ||
} | ||
into e | ||
select new TestCaseData(e.Head, e.Tail) | ||
.SetName("Head = [" + string.Join(", ", e.Head) + "], " + | ||
"Tail = [" + string.Join(", ", e.Tail) + "]") | ||
.Returns(e.Tail.Reverse().Concat(e.Head).ToArray()); | ||
|
||
[Test] | ||
public void PrependWithSharedSource() | ||
{ | ||
var first = new[] { 1 }.Prepend(2); | ||
var second = first.Prepend(3).Prepend(4); | ||
var third = first.Prepend(4).Prepend(8); | ||
|
||
second.AssertSequenceEqual(4, 3, 2, 1); | ||
third.AssertSequenceEqual(8, 4, 2, 1); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#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 | ||
{ | ||
/// <summary> | ||
/// Returns a sequence consisting of the head elements and the given tail element. | ||
/// </summary> | ||
/// <typeparam name="T">Type of sequence</typeparam> | ||
/// <param name="head">All elements of the head. Must not be null.</param> | ||
/// <param name="tail">Tail element of the new sequence.</param> | ||
/// <returns>A sequence consisting of the head elements and the given tail element.</returns> | ||
/// <remarks>This operator uses deferred execution and streams its results.</remarks> | ||
|
||
#if NET471_OR_GREATER || NETSTANDARD1_6_OR_GREATER || NETCOREAPP2_0_OR_GREATER | ||
public static IEnumerable<T> Append<T>(IEnumerable<T> head, T tail) | ||
#else | ||
public static IEnumerable<T> Append<T>(this IEnumerable<T> head, T tail) | ||
#endif | ||
{ | ||
if (head == null) throw new ArgumentNullException(nameof(head)); | ||
return head is PendNode<T> node | ||
? node.Concat(tail) | ||
: PendNode<T>.WithSource(head).Concat(tail); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.