Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 25, 2024 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baba-s/a8027ca05a831cbdee43c45e8247c4ea to your computer and use it in GitHub Desktop.
Save baba-s/a8027ca05a831cbdee43c45e8247c4ea to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
namespace Kogane
{
public static class IReadOnlyListExtensionMethods
{
public static T[] ShiftRight<T>
(
this IReadOnlyList<T> self,
int shiftCount
)
{
var count = self.Count;
var result = new T[ count ];
for ( var i = 0; i < count; i++ )
{
result[ i ] = self[ ( i - shiftCount + count ) % count ];
}
return result;
}
public static T[] ShiftLeft<T>
(
this IReadOnlyList<T> self,
int shiftCount
)
{
var count = self.Count;
var result = new T[ count ];
for ( var i = 0; i < count; i++ )
{
result[ i ] = self[ ( i + shiftCount ) % count ];
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment