Skip to content

Instantly share code, notes, and snippets.

@sgoguen
Created October 27, 2009 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgoguen/219575 to your computer and use it in GitHub Desktop.
Save sgoguen/219575 to your computer and use it in GitHub Desktop.
void Main()
{
var r = new Random().Values(0, 10).Let(list => list);
var l1 = r.Take(10);
var l2 = r.Take(10);
l1.SequenceEqual(l2).Dump("Should be equal");
var l3 = r.Take(20);
l3.Take(10).SequenceEqual(l1).Dump("Should start with same sequence");
var l4 = r.Take(20);
l3.SequenceEqual(l4);
}
}
public static class Extensions {
public static IEnumerable<int> Values(
this Random random,
int minValue, int maxValue)
{
while (true)
yield return random.Next(minValue, maxValue);
}
public static IEnumerable<U> Let<T, U>(this IEnumerable<T> source, Func<IEnumerable<T>, IEnumerable<U>> f) {
return f(source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment