Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (65 sloc) 1.516 kb
using System;
using System.Collections.Generic;
namespace ServiceStack.Common
{
public static class IntExtensions
{
public static IEnumerable<int> Times(this int times)
{
for (var i=0; i < times; i++)
{
yield return i;
}
}
public static void Times(this int times, Action<int> actionFn)
{
for (var i = 0; i < times; i++)
{
actionFn(i);
}
}
public static void Times(this int times, Action actionFn)
{
for (var i = 0; i < times; i++)
{
actionFn();
}
}
public static List<IAsyncResult> TimesAsync(this int times, Action<int> actionFn)
{
var asyncResults = new List<IAsyncResult>(times);
for (var i = 0; i < times; i++)
{
asyncResults.Add(actionFn.BeginInvoke(i, null, null));
}
return asyncResults;
}
public static List<IAsyncResult> TimesAsync(this int times, Action actionFn)
{
var asyncResults = new List<IAsyncResult>(times);
for (var i = 0; i < times; i++)
{
asyncResults.Add(actionFn.BeginInvoke(null, null));
}
return asyncResults;
}
public static List<T> Times<T>(this int times, Func<T> actionFn)
{
var list = new List<T>();
for (var i=0; i < times; i++)
{
list.Add(actionFn());
}
return list;
}
public static List<T> Times<T>(this int times, Func<int, T> actionFn)
{
var list = new List<T>();
for (var i=0; i < times; i++)
{
list.Add(actionFn(i));
}
return list;
}
}
}
Jump to Line
Something went wrong with that request. Please try again.