Skip to content

Instantly share code, notes, and snippets.

@yKimisaki
Last active July 30, 2019 08:00
Show Gist options
  • Save yKimisaki/a01be03c947fdac519b2 to your computer and use it in GitHub Desktop.
Save yKimisaki/a01be03c947fdac519b2 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Tonari.Linq
{
public static class Repetition
{
public static IEnumerable<T> Create<T>(Func<T> factory, int count)
{
return Create(_ => factory(), count);
}
public static IEnumerable<T> Create<T>(Func<int, T> factory, int count)
{
if (factory == null)
throw new ArgumentNullException("factory");
var createdCount = Mathf.Max(count, 0);
while (createdCount < count)
yield return factory(createdCount++);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment