Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why do I NOT need Publish on this cold observable?
- var subject = new List<string>
- {
- "test",
- "test",
- "hallo",
- "test",
- "hallo"
- }.ToObservable();
- subject
- .GroupBy(x => x)
- .SelectMany(grouped => grouped.Scan(0, (count, _) => ++count)
- .Zip(grouped, (count, chars) => new { Chars = chars, Count = count }))
- .Subscribe(result => Console.WriteLine("You typed {0} {1} times",
- result.Chars, result.Count));
- // I Would have expect that I need to use Publish like that
- //subject
- // .GroupBy(x => x)
- // .SelectMany(grouped => grouped.Publish(sharedGroup =>
- // sharedGroup.Scan(0, (count, _) => ++count)
- // .Zip(sharedGroup, (count, chars) =>
- // new { Chars = chars, Count = count })))
- // .Subscribe(result => Console.WriteLine("You typed {0} {1} times",
- // result.Chars, result.Count));
- Console.ReadLine();
- var subject = new List<Func<string>>
- {
- () =>
- {
- Console.WriteLine("performing");
- return "test";
- },
- () => "test",
- () => "hallo",
- () => "test",
- () => "hallo"
- }.ToObservable();
- subject
- .Select(x => x())
- .GroupBy(x => x)
- .SelectMany(grouped => grouped.Scan(0, (count, _) => ++count)
- .Zip(grouped, (count, chars) => new { Chars = chars, Count = count }))
- .Subscribe(result => Console.WriteLine("You typed {0} {1} times",
- result.Chars, result.Count));
- class Program
- {
- static void Main(string[] args)
- {
- var subject = new MyObservable();
- subject
- .GroupBy(x => x)
- .SelectMany(grouped => grouped.Scan(0, (count, _) => ++count)
- .Zip(grouped, (count, chars) => new { Chars = chars, Count = count }))
- .Subscribe(result => Console.WriteLine("You typed {0} {1} times",
- result.Chars, result.Count));
- Console.ReadLine();
- }
- }
- class MyObservable : IObservable<string>
- {
- public IDisposable Subscribe(IObserver<string> observer)
- {
- observer.OnNext("test");
- observer.OnNext("test");
- observer.OnNext("hallo");
- observer.OnNext("test");
- observer.OnNext("hallo");
- return Disposable.Empty;
- }
- }
Add Comment
Please, Sign In to add comment