Skip to content

Instantly share code, notes, and snippets.

@DeepSky8
Created March 24, 2016 18:10
Show Gist options
  • Save DeepSky8/e3eb573c07563f7a23b1 to your computer and use it in GitHub Desktop.
Save DeepSky8/e3eb573c07563f7a23b1 to your computer and use it in GitHub Desktop.
This compiles, and it makes perfect sense from a technical standpoint. But I don't know how I figured it out. And that bothers me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelectSoMany
{
public static class Program
{
static void Main(string[] args)
{
}
public static IEnumerable<T2> SelectTooMany<T, T2>(this IEnumerable<T> xs, Func<T, IEnumerable<T2>> f)
{
var result = new List<T2>();
var coll = xs.GetEnumerator();
while (coll.MoveNext())
{
var current = f(coll.Current);
foreach (var item in current)
{
result.Add(item);
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment