diff --git a/MoreLinq.Test/TuplewiseTest.g.cs b/MoreLinq.Test/TuplewiseTest.g.cs deleted file mode 100644 index bdb84e273..000000000 --- a/MoreLinq.Test/TuplewiseTest.g.cs +++ /dev/null @@ -1,86 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Phillip Palk. 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.Test -{ - using System; - using System.Collections.Generic; - using NUnit.Framework; - - [TestFixture] - public class TuplewiseTest - { - private void TuplewiseNWide(Func, TFunc, IEnumerable> tuplewise, TFunc resultSelector, IEnumerable source, params TResult[] fullResult) - { - var arity = resultSelector.GetType().GetGenericArguments().Length - 1; - - for (var i = 0; i < fullResult.Length; ++i) - using (var ts = source.Take(i).AsTestingSequence()) - Assert.That(tuplewise(ts, resultSelector), Is.EqualTo(fullResult.Take(i - arity + 1))); - } - - private void TuplewiseNWideInt(Func, TFunc, IEnumerable> tuplewise, TFunc resultSelector) - { - const int rangeLen = 100; - var arity = resultSelector.GetType().GetGenericArguments().Length - 1; - - TuplewiseNWide( - tuplewise, - resultSelector, - Enumerable.Range(1, rangeLen), - Enumerable.Range(1, rangeLen - (arity - 1)).Select(x => x * arity + Enumerable.Range(1, arity - 1).Sum()).ToArray() - ); - } - - private void TuplewiseNWideString(Func, TFunc, IEnumerable> tuplewise, TFunc resultSelector) - { - const string alphabet = "abcdefghijklmnopqrstuvwxyz"; - var arity = resultSelector.GetType().GetGenericArguments().Length - 1; - - TuplewiseNWide( - tuplewise, - resultSelector, - alphabet, - Enumerable.Range(0, alphabet.Length - (arity - 1)).Select(i => alphabet.Skip(i).Take(arity)).ToArray() - ); - } - - [Test] - public void TuplewiseIsLazy() - { - new BreakingSequence().Tuplewise(BreakingFunc.Of()); - new BreakingSequence().Tuplewise(BreakingFunc.Of()); - new BreakingSequence().Tuplewise(BreakingFunc.Of()); - } - - [Test] - public void TuplewiseIntegers() - { - TuplewiseNWideInt>((source, func) => MoreEnumerable.Tuplewise(source, func), (a, b ) => a + b ); - TuplewiseNWideInt>((source, func) => MoreEnumerable.Tuplewise(source, func), (a, b, c ) => a + b + c ); - TuplewiseNWideInt>((source, func) => MoreEnumerable.Tuplewise(source, func), (a, b, c, d) => a + b + c + d); - } - - [Test] - public void TuplewiseStrings() - { - TuplewiseNWideString>((source, func) => MoreEnumerable.Tuplewise(source, func), (a, b ) => string.Join(string.Empty, a, b )); - TuplewiseNWideString>((source, func) => MoreEnumerable.Tuplewise(source, func), (a, b, c ) => string.Join(string.Empty, a, b, c )); - TuplewiseNWideString>((source, func) => MoreEnumerable.Tuplewise(source, func), (a, b, c, d) => string.Join(string.Empty, a, b, c, d)); - } - } -} diff --git a/MoreLinq/Tuplewise.g.cs b/MoreLinq/Tuplewise.g.cs deleted file mode 100644 index 38b23bff7..000000000 --- a/MoreLinq/Tuplewise.g.cs +++ /dev/null @@ -1,152 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Phillip Palk. 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 a sequence resulting from applying a function to each - /// element in the source sequence and its - /// predecessor, with the exception of the first element which is - /// only returned as the predecessor of the second element. - /// - /// The type of the elements of . - /// The type of the elements of the returned sequence. - /// The source sequence. - /// A transform function to apply to each pair of . - /// Returns the resulting sequence. - /// is null - /// is null - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable Tuplewise(this IEnumerable source, Func resultSelector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e = source.GetEnumerator(); - - if (!e.MoveNext()) - yield break; - var predecessor1 = e.Current; - - while (e.MoveNext()) - { - yield return resultSelector(predecessor1, e.Current); - (predecessor1) = (e.Current); - } - } - } - - /// - /// Returns a sequence resulting from applying a function to each - /// element in the source sequence and its - /// 2 predecessors, with the exception of the first and second elements which are - /// only returned as the predecessors of the third element. - /// - /// The type of the elements of . - /// The type of the elements of the returned sequence. - /// The source sequence. - /// A transform function to apply to each triplet of . - /// Returns the resulting sequence. - /// is null - /// is null - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable Tuplewise(this IEnumerable source, Func resultSelector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e = source.GetEnumerator(); - - if (!e.MoveNext()) - yield break; - var predecessor1 = e.Current; - - if (!e.MoveNext()) - yield break; - var predecessor2 = e.Current; - - while (e.MoveNext()) - { - yield return resultSelector(predecessor1, predecessor2, e.Current); - (predecessor1, predecessor2) = (predecessor2, e.Current); - } - } - } - - /// - /// Returns a sequence resulting from applying a function to each - /// element in the source sequence and its - /// 3 predecessors, with the exception of the first 3 elements which are - /// only returned as the predecessors of the 4th element. - /// - /// The type of the elements of . - /// The type of the elements of the returned sequence. - /// The source sequence. - /// A transform function to apply to each 4-tuple of . - /// Returns the resulting sequence. - /// is null - /// is null - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable Tuplewise(this IEnumerable source, Func resultSelector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e = source.GetEnumerator(); - - if (!e.MoveNext()) - yield break; - var predecessor1 = e.Current; - - if (!e.MoveNext()) - yield break; - var predecessor2 = e.Current; - - if (!e.MoveNext()) - yield break; - var predecessor3 = e.Current; - - while (e.MoveNext()) - { - yield return resultSelector(predecessor1, predecessor2, predecessor3, e.Current); - (predecessor1, predecessor2, predecessor3) = (predecessor2, predecessor3, e.Current); - } - } - } - - } -}