Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / gtest-iter-33.cs
1 using System;
2 using System.Collections.Generic;
3
4 public delegate R Fun<A1,R>(A1 x);
5
6 class MyTest {
7   public static void Main(String[] args) {
8     foreach (Object d in Map<int,int,String,Object>
9                             (delegate (int x) { return x.ToString(); }, 
10                              FromTo(10,20)))
11       Console.WriteLine(d);
12   }
13
14   // Map with argument/result co/contravariance:
15   // Aa=argument, Rr=result, Af=f's argument, Rf=f's result
16
17   public static IEnumerable<Rr> Map<Aa,Af,Rf,Rr>(Fun<Af,Rf> f, 
18                                                  IEnumerable<Aa> xs) 
19     where Aa : Af 
20     where Rf : Rr 
21   { 
22     foreach (Aa x in xs)
23       yield return f(x);    // gmcs 1.1.9 bug: cannot convert Aa to Af
24   }
25
26   // FromTo : int * int -> int stream
27
28   public static IEnumerable<int> FromTo(int from, int to) { 
29     for (int i=from; i<=to; i++)
30       yield return i;
31   }
32 }
33
34