Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // map自体は、.NETでは.select拡張メソッドとして提供されているかんじっぽい?
- // old
- static int[]
- squarefunc(int[] lis)
- {
- for(var i = 0; i <= lis.Count() -1; ++i)
- {
- lis[i] = lis[i] * lis[i];
- }
- return lis;
- }
- // plain
- static IEnumerable<T>
- map<T>(IEnumerable<T> lis, Func<T,T> func)
- {
- var result = new List<T>();
- foreach (T val in lis ){ result.Add(func(val)); };
- return result;
- }
- // closure
- static Func<IEnumerable<T>, IEnumerable<T>>
- clomap<T>(Func<T,T> func)
- {
- Func<IEnumerable<T>, IEnumerable<T>> f =
- (IEnumerable<T> lis) =>
- {
- //ここの部分は一行で書くとlis.select(func)になる
- var result = new List<T>();
- foreach(T val in lis) {result.Add(func(val));};
- return result;
- };
- return f;
- }
Add Comment
Please, Sign In to add comment