Last active
July 30, 2019 08:00
-
-
Save yKimisaki/a01be03c947fdac519b2 to your computer and use it in GitHub Desktop.
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
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