Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created August 10, 2012 04:58
Show Gist options
  • Save masaru-b-cl/3311170 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/3311170 to your computer and use it in GitHub Desktop.
ReactiveFizzBuzz
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