🍊
ドドスコード with Reactive Extensions
Of https://twitter.com/Sheeeeepla/status/1554028833942441984
I thought it was a good idea to write it in Reactive Extensions, but it seems wrong.
using System.Reactive.Linq;
var expected = new[] { "ドド", "スコ", "スコ", "スコ", "ドド", "スコ", "スコ", "スコ", "ドド", "スコ", "スコ", "スコ" };
IEnumerable<string> Gen()
{
var rnd = new Random();
var words = new[] { "ドド", "スコ" };
while (true)
{
Thread.Sleep(1000);
yield return words[rnd.Next(0, 2)];
}
}
var q = new Queue<string>(Enumerable.Repeat(string.Empty,expected.Length));
var burk = Gen().ToObservable();
burk.TakeUntil(x => {
q.Dequeue();
q.Enqueue(x);
return q.SequenceEqual(expected);
}).Subscribe(Console.WriteLine,ex=>throw ex,()=>Console.WriteLine("ラブ注入♡"));
Discussion