Created
April 6, 2017 17:33
-
-
Save fliedonion/eda9667d4d0c6f8c4a366da9556dac52 to your computer and use it in GitHub Desktop.
Reactive Extensions Zip FizzBuzz
This file contains 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.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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result