コード例 #1
0
 static IEnumerable <int> FluentSyntax(string mode) =>
 (Enumerable.Range(0, int.MaxValue)
  .Select(pass => new { pass, counter = Readers.Counter(0) })
  .Select(_ => gcdStartStates.Where(state => predicate(_.pass, _.counter()))
          .Select(state => state)
          )
 ).Where(list =>
         (Gcd.Run(list.ToList())
          .SelectMany(_ => ConsoleWrite(Prompt(mode)), (_, __) => new {})
          .SelectMany(_ => ConsoleReadKey(), (_, c) => new { c })
          .SelectMany(_ => ConsoleWriteLine(), (_, __) => ToUpper(_.c.KeyChar) == 'Q')
         ).Invoke()
         ).Select(list => 0
                  );
コード例 #2
0
 static IEnumerable <int> ComprehensionSyntax2(string mode) =>
 (from list in (from pass in Enumerable.Range(0, int.MaxValue)
                let counter = Readers.Counter(0)
                              select from state in gcdStartStates
                                  where predicate(pass, counter())
                              select state
                )
      where (from _   in Gcd.Run2(list.ToList()) | IO <Unit> .Empty
             from __  in ConsoleWrite(Prompt(mode))
             from c   in ConsoleReadKey()
             from ___ in ConsoleWriteLine()
             select ToUpper(c.KeyChar) == 'Q'
             ).Invoke()
  select 0
 );
コード例 #3
0
                              ).FirstOrDefault(); // Doesn't assume result list non-empty, unlike: ).First();

        static IEnumerable <int> ImperativeSyntax(string mode)
        {
            for (int pass = 0; pass < int.MaxValue; pass++)
            {
                var counter = 0;
                var list    = gcdStartStates.Where(state => predicate(pass, counter++));

                Gcd.Run(list.ToList());
                Console.Write(Prompt(mode));
                var c = Console.ReadKey();
                Console.WriteLine();

                if (ToUpper(c.KeyChar) == 'Q')
                {
                    yield return(0);                           //break;
                }
            }
            //      return 0;
        }