c#仿lisp的mapcar函数
/// <summary>
/// 仿lisp的mapcar函数
/// </summary>
/// <typeparam name="T1">集合</typeparam>
/// <typeparam name="T2">集合</typeparam>
/// <typeparam name="TR"></typeparam>
/// <param name="lst1"></param>
/// <param name="lst2"></param>
/// <param name="func"></param>
/// <returns></returns>
//List<double> 1st1 = new List<double>{1,2,3, 4} :
//List<double> 1st2 = new List<double> { 1, 2, 3, 4 } :
//var 1st3 = Mapcar(1st1, 1st2, (a, b) => a + b) :
public static IEnumerable<TR> Mapcar<T1, T2, TR>(IEnumerable<T1> lst1, IEnumerable<T2> lst2, Func<T1, T2, TR> func)
{
var itor1 = lst1.GetEnumerator();
var itor2 = lst2.GetEnumerator();
while (itor1.MoveNext() && itor2.MoveNext())
yield return func(itor1.Current, itor2.Current);
}
您可能还需要C#中的yield关键字的参考.
(完)