Skip to content

Instantly share code, notes, and snippets.

@huangcd
Created July 18, 2012 00:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save huangcd/3133167 to your computer and use it in GitHub Desktop.
Save huangcd/3133167 to your computer and use it in GitHub Desktop.
a map function like python in C#
public static IEnumerable<TResult> Map<in TSource, TResult>(IEnumerable<TSource> sources, Func<TSource, TResult> mapper)
{
foreach (var source in sources)
{
yield return mapper(source);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment