Skip to content

Instantly share code, notes, and snippets.

@fliedonion
Created April 6, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliedonion/eda9667d4d0c6f8c4a366da9556dac52 to your computer and use it in GitHub Desktop.
Save fliedonion/eda9667d4d0c6f8c4a366da9556dac52 to your computer and use it in GitHub Desktop.
Reactive Extensions Zip FizzBuzz
using System;
using System.Linq;
using System.Reactive.Linq;
namespace RxZipFizzBuzz
{
class Program
{
static void Main(string[] args)
{
var numberObserver = Observable.Range(1, 30);
var no = numberObserver.Select(i => i % 3 != 0 && i % 5 != 0 ? i.ToString() : "");
var fo = new[] { "", "", "FIZZ" }.ToObservable().Repeat(10);
var bo = new[] { "", "", "", "", "BUZZ" }.ToObservable().Repeat(6);
Observable.Zip(no, fo, bo).Subscribe(x => Console.WriteLine( $"{x[0]}{x[1]}{x[2]}"));
Console.ReadKey();
}
}
}
@fliedonion
Copy link
Author

result

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment