Last active
April 7, 2017 02:54
-
-
Save fliedonion/0cf4b911815eba2d815564417a88ea92 to your computer and use it in GitHub Desktop.
Reactive Extensions And/Then/When 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 RxAndThenWhenFizzBuzz { | |
class Program { | |
static void Main(string[] args) { | |
var numberObserver = Observable.Range(1, 30); | |
var fizzObserver = numberObserver.Select(i => i % 3 == 0 ? "Fizz" : ""); | |
var buzzObserver = numberObserver.Select(i => i % 5 == 0 ? "Buzz" : ""); | |
var plan = numberObserver | |
.And(fizzObserver) | |
.And(buzzObserver) | |
.Then((i, f, b) => f + b == "" ? i.ToString() : f + b); | |
Observable.When(plan).Subscribe(Console.WriteLine); | |
Console.ReadKey(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result