Skip to content

Commit

Permalink
Adding some ruby-inspired extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwingfield committed Jun 15, 2011
1 parent 9a1f3b5 commit dfe7d46
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin
obj
TestResults
*~
*.swp
*.sln
*.suo
sugar
Empty file added Enumerables.cs
Empty file.
44 changes: 44 additions & 0 deletions Numbers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Faker.Extensions
{
public static class NumberExtensions
{
public static IEnumerable<int> To(this int from, int to)
{
if (to >= from)
{
for (int i = from; i <= to; i++)
{
yield return i;
}
}
else
{
for (int i = to; i >= from; i--)
{
yield return i;
}
}
}

public static IEnumerable<T> Times<T>(this int num, T toReturn)
{
for (int i = 0; i < num; i++)
{
yield return toReturn;
}
}

public static IEnumerable<T> Times<T>(this int num, Func<int, T> block)
{
for (int i = 0; i < num; i++)
{
yield return block(i);
}
}
}
}

0 comments on commit dfe7d46

Please sign in to comment.