Slides license: Creative Commons Attribution Non-Commercial Share Alike See
Rx is a library for composing asynchronous and event-based programs using observable collections. Queries? LINQ? Too hard today…
You could get stuck C# 4.0 covariance
You could get stuck C# 4.0 covariance (Waiting to move next) moving on
Source:
Reversing arrows… Input becomes output and vice versa Making a U-turn in synchrony
C# didn’t borrow Java checked exceptions
IDisposable ( & ) IEnumerator GetEnumerator( void ); We really got an enumerator and a disposable
void IEnumerator IEnumerableDual IEnumerable ) GetEnumerator( Set Will only dualize the synchrony aspect
This is an output too
Discrete domain with true and false
If you got true, you really got a T T
If you got false, you really got void void
(T | void | Exception) MoveNext( void But C# doesn’t have discriminated unions… Let’s splat this into three methods instead! But C# doesn’t have discriminated unions… Let’s splat this into three methods instead! Got IEnumeratorDual IEnumerator IEnumeratorDual>); IEnumerator x);
Source:
Used to detach the observer… Do you really know C# 4.0?
(*) Visit
You could get flooded C# 4.0 contravariance
Environment MoveNext Got next? Application OnNext Have next! IEnumerable IEnumerator IObservable IObserver Interactive Reactive
OnCompleted OnNext OnError new int[0] new[] { 42 } Throwing iterator Iterator that got stuck Notion of time
OnNext(0) OnNext(1) OnNext(2) yield 0 yield 1 yield 2
Hypothetical anonymous iterator syntax in C# Synchronous Asynchronous A variant with time notion exists (GenerateWithTime)
C# doesn’t have anonymous interface implementation, so we provide various extension methods that take lambdas. C# 4.0 named parameter syntax
F10F10
F10F10
F5F5
Breakpoint got hit
Lack of composition Resource maintenance?
Can define operators Resource maintenance!
Lack of composition Exceptions?Exceptions? Synchronous completion? Cancel?Cancel? State?State?
React TextChanged Asynchronous request Reaction Reactive Reactor Data binding on UI thread
input.SelectMany(term => lookup(term))
input Service call 1 Service call 2 UI data binding |R|Re|Rea|Reac|React| Reacti| Reactiv| Reactive| Reactive Reaction Reactive Reactor Source:
input Service call 1 Service call 2 UI data binding |R|Re|Rea|Reac|React| Reacti| Reactiv| Reactive| Reactive Take Until
// Alternative approach for composition using: // IObservable Switch (IObservable > sources) var res = (from term in input select lookup(term)).Switch(); Very local fix Hops from source to source
IEnumerable E.g. LINQ to Objects IObservable E.g. LINQ to Events IQueryable E.g. LINQ to SQL Fixed (MSIL) Translatable (Expression trees) ToQueryable ToObservable ToEnumerable AsQueryable AsEnumerable AsQbservable AsObservable Pull (interactive) Push (reactive) Concurrency (IScheduler) LINQ to *.* What? Where? How? Worker pools Message loops Threads Distributed Duality Homo-iconic IQbservable E.g. LINQ to PowerShell ToQbservable
Rx is a library for composing asynchronous and event-based programs using observable collections. Queries! LINQ! Way simpler with Rx