Skip to content

Instantly share code, notes, and snippets.

@cwharris
Created November 5, 2013 16:16
Show Gist options
  • Save cwharris/7321527 to your computer and use it in GitHub Desktop.
Save cwharris/7321527 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
Func<int, int, int> add = (a, b) => a + b;
var obs1 = Observable.Empty<int>().Scan(add);
var obs2 = Observable.Empty<int>().Scan(0, add);
var obs3 = Observable.Range(1, 3).Scan(add);
var obs4 = Observable.Range(1, 3).Scan(0, add);
obs1.Subscribe(CreateObserver<int>("1"));
obs2.Subscribe(CreateObserver<int>("2"));
obs3.Subscribe(CreateObserver<int>("3"));
obs4.Subscribe(CreateObserver<int>("4"));
Console.ReadLine();
}
public static IObserver<T> CreateObserver<T>(string name)
{
return Observer.Create<T>(
next =>
{
Console.WriteLine("next {0}:{1}", name, next);
},
error =>
{
Console.WriteLine(error);
},
() =>
{
Console.WriteLine("completed {0}", name);
}
);
}
}
completed 1
completed 2
next 3:1
next 3:3
next 3:6
completed 3
next 4:1
next 4:3
next 4:6
completed 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment