-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36bff43
commit e9bd00c
Showing
9 changed files
with
111 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
namespace Hussy.Net; | ||
|
||
/// <summary> | ||
/// Defines static methods for common programming tasks. | ||
/// </summary> | ||
public static partial class Hussy | ||
{ | ||
/// <summary> | ||
/// Generates a range of values starting with <c>1</c> through the specified <paramref name="count"/> value. | ||
/// </summary> | ||
/// <param name="count">The maximum value to include in the range.</param> | ||
/// <returns>A range of values starting with <c>1</c> through the specified <paramref name="count"/> value.</returns> | ||
public static IEnumerable<IEnumerable<int>> Gbr(int count, int batchSize) => | ||
Enumerable.Range(1, count).Chunk(batchSize); | ||
|
||
/// <summary> | ||
/// Generates a range of values from the specified <paramref name="start"/> through the specified <paramref name="count"/> value. | ||
/// </summary> | ||
/// <param name="start">The starting value for the range.</param> | ||
/// <param name="count">The maximum value to include in the range.</param> | ||
/// <returns>A range of values starting with <paramref name="start"/> through the specified <paramref name="count"/> value.</returns> | ||
public static IEnumerable<IEnumerable<int>> Gbr(int start, int count, int batchSize) => | ||
Enumerable.Range(start, count).Chunk(batchSize); | ||
|
||
/// <summary> | ||
/// Generates a range of values from the specified <paramref name="start"/> through the specified <paramref name="count"/> value. | ||
/// </summary> | ||
/// <param name="start">The starting value for the range.</param> | ||
/// <param name="count">The maximum value to include in the range.</param> | ||
/// <param name="stepSize">The step value to use when generating the range.</param> | ||
/// <returns>A range of values starting with <paramref name="start"/> through the specified <paramref name="count"/> value.</returns> | ||
public static IEnumerable<IEnumerable<int>> Gbr(int start, int count, int stepSize, int batchSize) | ||
{ | ||
List<int> range = new(capacity: count); | ||
for (int i = 0; i < count; i++) | ||
{ | ||
range.Add(start); | ||
start += stepSize; | ||
} | ||
|
||
return range.Chunk(batchSize); | ||
} | ||
} |
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
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,17 @@ | ||
namespace Hussy.Net; | ||
|
||
/// <summary> | ||
/// Defines static methods for common programming tasks. | ||
/// </summary> | ||
public static partial class Hussy | ||
{ | ||
/// <summary> | ||
/// Batches the specified <paramref name="source"/> sequence into chunks of the specified <paramref name="size"/>. | ||
/// </summary> | ||
/// <param name="source">Specifies the source sequence to batch.</param> | ||
/// <param name="size">Specifies the size of the individual batches.</param> | ||
/// <typeparam name="T">Specifies the type of the data in the <paramref name="source"/> sequence.</typeparam> | ||
/// <returns>A collection of batches created from the specified <paramref name="source"/> sequence.</returns> | ||
public static IEnumerable<IEnumerable<T>> B<T>(this IEnumerable<T> source, int size = 2) => | ||
source.Chunk(size); | ||
} |
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,10 @@ | ||
namespace Hussy.Net; | ||
|
||
/// <summary> | ||
/// Defines static methods for common programming tasks. | ||
/// </summary> | ||
public static partial class Hussy | ||
{ | ||
public static string J<T>(this IEnumerable<T> source, string separator = ", ") => | ||
string.Join(separator, source); | ||
} |
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,36 @@ | ||
namespace Hussy.Net; | ||
|
||
/// <summary> | ||
/// Defines static methods for common programming tasks. | ||
/// </summary> | ||
public static partial class Hussy | ||
{ | ||
/// <summary> | ||
/// Creates a classic array string (e.g. <c>[1, 2, 3]</c>) for the specified sequence. | ||
/// </summary> | ||
/// <param name="sequence">The sequence to create the array string for.</param> | ||
/// <typeparam name="T">Specifies the type of data in the sequence.</typeparam> | ||
/// <returns>The input sequence wrapped in square brackets and separated by commas and spaces.</returns> | ||
/// <example> | ||
/// Behind the scenes, this method simply interpolates a call to <c>string.Join</c> with <c>", "</c> as the | ||
/// separator. This results in an output string of <c>[1, 2, 3, ...]</c>, to use it, simply specify a collection | ||
/// parameter: | ||
/// | ||
/// <code> | ||
/// // Generate a range to work with: | ||
/// var sequence = Gr(5); | ||
/// | ||
/// // Create the formatted string: | ||
/// var output = Far(sequence); | ||
/// | ||
/// // Append the output to the output stream: | ||
/// A(output); | ||
/// </code> | ||
/// | ||
/// The expected output of the above snippet is: | ||
/// | ||
/// > [1, 2, 3, 4, 5] | ||
/// </example> | ||
public static string Far<T>(IEnumerable<T> sequence) => | ||
$"[{string.Join(", ", sequence)}]"; | ||
} |