Created
January 12, 2017 19:15
-
-
Save heltonbiker/2075c1ba089f695b9f9294c9bc551e66 to your computer and use it in GitHub Desktop.
Method that aims to distribute a sequence amongst N other sequences, cyclically, like dealing cards.
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; | |
using System.Reactive.Subjects; | |
namespace UnzipRx | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var source = new Subject<int>(); | |
int count = 3; | |
source.Select((t, i) => Tuple.Create(t, i)) | |
.GroupBy(t => t.Item2 % count) | |
.Select(g => g.Select(t => t.Item1)) | |
.Do(s => s.Subscribe(Console.WriteLine)); | |
Observable.Range(0, 20).Subscribe(source); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, regarding legitimate vs pointless use of subject, currently I am using it in the following class, according to this advice:
It's only purpose is to "enter the monad", that is, go from
IEnumerable<double>
, via sequentialAddSamplesInternal()
calls, toIObservable<double>
via the subscribableWhenNewSamples
property.What led me to think this use is legitimate is the following part of the advice:
So I wonder if I should worry about this Subject, or not.