[jit] Fix the saving of the 'cfg->ret_var_set' flag when inlining, it was set to...
[mono.git] / mcs / tests / gtest-iter-06.cs
1 using System;
2 using System.Collections.Generic;
3
4 namespace Mono.Rocks
5 {
6         public static class KeyValuePair
7         {
8                 public static KeyValuePair<TKey, TValue>? Just<TKey, TValue> (TKey key, TValue value)
9                 {
10                         return new KeyValuePair<TKey, TValue> (key, value);
11                 }
12         }
13
14         public static class Sequence
15         {
16                 public static IEnumerable<TResult> Unfoldr<TSource, TResult> (TSource value, Func<TSource, KeyValuePair<TResult, TSource>?> func)
17                 {
18                         return CreateUnfoldrIterator (value, func);
19                 }
20
21                 private static IEnumerable<TResult> CreateUnfoldrIterator<TSource, TResult> (TSource value, Func<TSource, KeyValuePair<TResult, TSource>?> func)
22                 {
23                         KeyValuePair<TResult, TSource>? r;
24                         while ((r = func (value)).HasValue) {
25                                 KeyValuePair<TResult, TSource> v = r ?? new KeyValuePair<TResult, TSource> ();
26                                 yield return v.Key;
27                                 value = v.Value;
28                         }
29                 }
30         }
31
32         class Test
33         {
34                 public static int Main ()
35                 {
36                         IEnumerable<int> x = Sequence.Unfoldr (10, b => b == 0
37                                 ? null
38                                 : KeyValuePair.Just (b, b - 1));
39
40                         int i = 10;
41                         foreach (int e in x) {
42                                 Console.WriteLine (e);
43                                 if (i-- != e)
44                                         return 1;
45                         }
46                         
47                         return 0;
48                 }
49         }
50 }