- 
                Notifications
    
You must be signed in to change notification settings  - Fork 420
 
Added Tuplewise operator #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            jonasdmentia
  wants to merge
  6
  commits into
  morelinq:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
jonasdmentia:add-tuplewise-operator
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 4 commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0ec9b4f
              
                Added Tuplewise operator
              
              
                jonasdmentia 297e912
              
                Fixed mistake in .csproj description.
              
              
                jonasdmentia 8e683b6
              
                Apply suggestions for code simplication from code review
              
              
                jonasdmentia d6a99b3
              
                Move methods that don't need to be templated out of the TuplewiseTest…
              
              
                jonasdmentia 9607605
              
                Merge branch 'master' into add-tuplewise-operator
              
              
                jonasdmentia 1a4df25
              
                Merge remote-tracking branch 'upstream/master' into add-tuplewise-ope…
              
              
                atifaziz File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or 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,64 @@ | ||
| #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 partial class TuplewiseTest | ||
| { | ||
| // NOTE: See the T4 template TuplewiseTest.g.tt for the actual tests | ||
| 
     | 
||
| void TuplewiseNWide<TSource, TResult, TFunc>(Func<IEnumerable<TSource>, TFunc, IEnumerable<TResult>> tuplewise, TFunc resultSelector, IEnumerable<TSource> 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))); | ||
| } | ||
| 
     | 
||
| void TuplewiseNWideInt<TFunc>(Func<IEnumerable<int>, TFunc, IEnumerable<int>> 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() | ||
| ); | ||
| } | ||
| 
     | 
||
| void TuplewiseNWideString<TFunc>(Func<IEnumerable<char>, TFunc, IEnumerable<string>> 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() | ||
| ); | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or 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,50 @@ | ||
| #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; | ||
| 
     | 
||
| public partial class TuplewiseTest | ||
| { | ||
| [Test] | ||
| public void TuplewiseIsLazy() | ||
| { | ||
| new BreakingSequence<object>().Tuplewise(BreakingFunc.Of<object, object, int>()); | ||
| new BreakingSequence<object>().Tuplewise(BreakingFunc.Of<object, object, object, int>()); | ||
| new BreakingSequence<object>().Tuplewise(BreakingFunc.Of<object, object, object, object, int>()); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void TuplewiseIntegers() | ||
| { | ||
| TuplewiseNWideInt<Func<int, int, int>>(MoreEnumerable.Tuplewise, (a, b ) => a + b ); | ||
| TuplewiseNWideInt<Func<int, int, int, int>>(MoreEnumerable.Tuplewise, (a, b, c ) => a + b + c ); | ||
| TuplewiseNWideInt<Func<int, int, int, int, int>>(MoreEnumerable.Tuplewise, (a, b, c, d) => a + b + c + d); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void TuplewiseStrings() | ||
| { | ||
| TuplewiseNWideString<Func<char, char, string>>(MoreEnumerable.Tuplewise, (a, b ) => string.Join(string.Empty, a, b )); | ||
| TuplewiseNWideString<Func<char, char, char, string>>(MoreEnumerable.Tuplewise, (a, b, c ) => string.Join(string.Empty, a, b, c )); | ||
| TuplewiseNWideString<Func<char, char, char, char, string>>(MoreEnumerable.Tuplewise, (a, b, c, d) => string.Join(string.Empty, a, b, c, d)); | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or 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,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) 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; | ||
| 
     | 
||
| public partial class TuplewiseTest | ||
| { | ||
| <# const int max = 4; | ||
| const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ||
| #> | ||
| [Test] | ||
| public void TuplewiseIsLazy() | ||
| { | ||
| <# for (var i = 2; i <= max; ++i) { | ||
| var funcTypeArgs = string.Join(" ", Enumerable.Repeat("object,", i).Concat(Enumerable.Repeat(" ", max - i))); | ||
| #> | ||
| new BreakingSequence<object>().Tuplewise(BreakingFunc.Of<<#= funcTypeArgs #> int>()); | ||
| <# } #> | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void TuplewiseIntegers() | ||
| { | ||
| <# for (var i = 2; i <= max; ++i) { | ||
| var funcTypeArgs = string.Join(" ", Enumerable.Repeat("int,", i).Concat(Enumerable.Repeat(" ", max - i))); | ||
| var functorArgs = string.Join(", ", Enumerable.Range(1, i).Select(j => alphabet.Substring(j - 1, 1))) + new string(' ', 3 * (max - i)); | ||
| var functorBody = string.Join(" + ", Enumerable.Range(1, i).Select(j => alphabet.Substring(j - 1, 1))) + new string(' ', 4 * (max - i)); | ||
| #> | ||
| TuplewiseNWideInt<Func<<#= funcTypeArgs #> int>>(MoreEnumerable.Tuplewise, (<#= functorArgs #>) => <#= functorBody #>); | ||
| <# } #> | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void TuplewiseStrings() | ||
| { | ||
| <# for (var i = 2; i <= max; ++i) { | ||
| var funcTypeArgs = string.Join(" ", Enumerable.Repeat("char,", i).Concat(Enumerable.Repeat(" ", max - i))); | ||
| var functorArgs = string.Join(", ", Enumerable.Range(1, i).Select(j => alphabet.Substring(j - 1, 1))) + new string(' ', 3 * (max - i)); | ||
| #> | ||
| TuplewiseNWideString<Func<<#= funcTypeArgs #> string>>(MoreEnumerable.Tuplewise, (<#= functorArgs #>) => string.Join(string.Empty, <#= functorArgs #>)); | ||
| <# } #> | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or 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.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what this is and do we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's because I've added the T4 template to the test project. I don't believe it's 'needed' as far as building is concerned, but I think it's basically a tag used by the IDE to expose certain things for the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that's what the service in the following line was but seems
82a7f48d-3b50-4b1e-b82e-3ada8210c358is for tests so this one must be for T4. I was just surprised it wasn't already there since we've been using T4 since a long time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in MoreLinq.Test project, until now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that certainly explains it, @Orace!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we'll need
tt.sh/tt.cmdto cover the test project as well now.