Skip to content

Provides a simple range-like syntax for integer iterations through clever hacks.

License

Notifications You must be signed in to change notification settings

BrunoZell/Enumerizer

Repository files navigation

Enumerizer

A mini utility that provides a declarative way to iterate integers:

// Import Enumerizer in each file you want to use it
using static Enumerizer;

// 0 1 2 3 4 5 6 7 8 9
foreach (int i in 0 <= i < 10)
    Console.Write(i + " ");

// 10 9 8 7 6 5 4 3 2 1 0
foreach (int i in 10 >= i >= 0)
    Console.Write(i + " ");

// 10 8 6 4 2 0
foreach (int i in 10 >= i >= 0 | 2)
    Console.Write(i + " ");

// -13 -10 -7 -4 -1 2 5 8
foreach (int i in -14 < i <= 10 | 3)
    Console.Write(i + " ");

A usage with Linq is also possible:

using System.Linq;
using static Enumerizer;

// [ -3, -2, -1, 0, 1, 2, 3 ]
int[] it = (-3 <= i <= 3).ToArray();

About

Provides a simple range-like syntax for integer iterations through clever hacks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages