Created
August 10, 2012 04:58
-
-
Save masaru-b-cl/3311170 to your computer and use it in GitHub Desktop.
ReactiveFizzBuzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Reactive.Linq; | |
namespace ReactiveFizzBuzz | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
IObservable<string> fizzbuzz = FizzBuzz(); | |
fizzbuzz.Take(20).Subscribe(Console.WriteLine); | |
} | |
private static IObservable<string> FizzBuzz() | |
{ | |
return Observable.Generate( | |
1, | |
_ => true, | |
i => i + 1, | |
i => i % 15 == 0 ? "FizzBuzz" | |
: i % 3 == 0 ? "Fizz" | |
: i % 5 == 0 ? "Buzz" | |
: i.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment