Difference between revisions of "NET Reactive Framework"
From JVMLangSummit
Jump to navigationJump to search (→.NET Reactive) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
; Project: | ; Project: | ||
; Blog: | ; Blog: | ||
− | ; Slides: [[Image: | + | ; Slides: [[Image:Meijer_Rx.pdf]] |
=== Abstract === | === Abstract === | ||
− | + | The .NET Reactive Framework — Erik Meijer | |
+ | The .NET Reactive Framework (Rx) is an abstraction of the well-known Subject/Observer pattern derived as the mathematical dual of the iterator pattern. | ||
+ | |||
+ | We show how Rx can be used to program against event streams and asynchronous computations using LINQ syntax as well as using good old imperative code. | ||
+ | |||
+ | = Types = | ||
+ | (roughly translated to roughly-Java syntax) | ||
+ | == Enumerable == | ||
+ | <pre> | ||
+ | interface Enumerable<T> { | ||
+ | Enumerator<T> getEnumerator(); | ||
+ | } | ||
+ | |||
+ | interface Enumerator<T throws E> extends Disposable { | ||
+ | bool moveNext(); | ||
+ | T current() throws E; | ||
+ | } | ||
+ | </pre> | ||
+ | == Observable == | ||
+ | <pre> | ||
+ | interface Observable<T> { | ||
+ | // dual to getEnumerator: | ||
+ | Disposable putObserver(Observer<? extends T> o); | ||
+ | } | ||
+ | |||
+ | // dual to Enumerator, except that Disposable is not dualized: | ||
+ | interface Observer<T throws E> extends Disposable { | ||
+ | // dual to moveNext returning false: | ||
+ | void onCompleted(); | ||
+ | // dual to current() returning x: | ||
+ | void onNext(T x) ; | ||
+ | // dual to current() throwing e: | ||
+ | void onError(E e) ; | ||
+ | } | ||
+ | </pre> | ||
+ | == Subject == | ||
+ | <pre> | ||
+ | interface Subject<S,T> extends Observer<S>, Observable<T> { | ||
+ | // observes values of type S, produces values of type T | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | = Related Work = | ||
+ | * F# first-class events | ||
+ | * F# async workflows | ||
+ | * Thomas P. Reactive LINKQ (in F#) | ||
+ | * Esterelle, Lustre, ... | ||
+ | * Functional Reactive Programming (has continuous time) | ||
+ | * Unix pipes, PowerShell, SSIS, WWF (push-based data flow | ||
+ | * Promises are like Subjects, with single event produced | ||
+ | |||
+ | With Promises, the language does lifting, e.g.: <tt>ps: Promise[String] => ps.length: Promise[int]</tt> | ||
+ | <br>LINQ does not lift, is explicit: <tt>from ps ... select ps.length ...</tt> | ||
= Current Status = | = Current Status = |
Latest revision as of 16:28, 17 September 2009
Contents
.NET Reactive Framework
Erik Meijer, Microsoft
- Project
- Blog
- Slides
- File:Meijer Rx.pdf
Abstract
The .NET Reactive Framework — Erik Meijer
The .NET Reactive Framework (Rx) is an abstraction of the well-known Subject/Observer pattern derived as the mathematical dual of the iterator pattern.
We show how Rx can be used to program against event streams and asynchronous computations using LINQ syntax as well as using good old imperative code.
Types
(roughly translated to roughly-Java syntax)
Enumerable
interface Enumerable<T> { Enumerator<T> getEnumerator(); } interface Enumerator<T throws E> extends Disposable { bool moveNext(); T current() throws E; }
Observable
interface Observable<T> { // dual to getEnumerator: Disposable putObserver(Observer<? extends T> o); } // dual to Enumerator, except that Disposable is not dualized: interface Observer<T throws E> extends Disposable { // dual to moveNext returning false: void onCompleted(); // dual to current() returning x: void onNext(T x) ; // dual to current() throwing e: void onError(E e) ; }
Subject
interface Subject<S,T> extends Observer<S>, Observable<T> { // observes values of type S, produces values of type T }
Related Work
- F# first-class events
- F# async workflows
- Thomas P. Reactive LINKQ (in F#)
- Esterelle, Lustre, ...
- Functional Reactive Programming (has continuous time)
- Unix pipes, PowerShell, SSIS, WWF (push-based data flow
- Promises are like Subjects, with single event produced
With Promises, the language does lifting, e.g.: ps: Promise[String] => ps.length: Promise[int]
LINQ does not lift, is explicit: from ps ... select ps.length ...
Current Status
Future
Key Issues for Discussion
(please expand cooperatively)