SlideShare a Scribd company logo
1 of 44
Download to read offline
Reactive Programming
   and Framework
   Zhao Jie - SNDA - Sep. 2010
About me
     /      / Jeffrey Zhao /



Blog: http://blog.zhaojie.me/

Twitter: @jeffz_cn

F#, Scala, JavaScript, Python, .NET, mono...

Java (as the language) hater
What?

Fundamentally change the way you
   think about coordinating and
  orchestrating asynchronous and
     event-based programming
Why?

   Because the essence of
      Cloud, Web, Mobile
is asynchronous computations
How?

By showing that asynchronous and
 event-base computations are just
      push-based collections
Interactive & Reactive
a := b + c
Interactive                 Reactive
              Environment




               Program
Let’s implement both
  interfaces with...
Enumerable Collections

  interface	
  IEnumerable<out	
  T>
  {
  	
  	
  	
  	
  IEnumerator<T>	
  GetEnumerator();
  }

  interface	
  IEnumerator<out	
  T>
  {
  	
  	
  	
  	
  bool	
  MoveNext();
  	
  	
  	
  	
  T	
  Current	
  {	
  get;	
  }
  }
1
                                            Enumerator
                      GetEnumerator()



                       Current

                                 3
                                                     2
                                        MoveNext()

  Consumer pulls
successive elements                         true/false
from the collection
Dualize Enumerable
      Collections
interface	
  IEnumerable<out	
  T>
{
	
  	
  	
  	
  //	
  void	
  -­‐>	
  enumerator
	
  	
  	
  	
  IEnumerator<T>	
  GetEnumerator();
}

interface	
  IObservable<out	
  T>
{
	
  	
  	
  	
  //	
  observer	
  -­‐>	
  void
	
  	
  	
  	
  IDisposable	
  Subscribe(IObserver<T>	
  o)
}
Dualize Enumerable
                  Collections
interface	
  IEnumerator<out	
  T>
{
	
  	
  	
  	
  bool	
  MoveNext();	
  //	
  void	
  -­‐>	
  bool
	
  	
  	
  	
  T	
  Current	
  {	
  get;	
  }	
  //	
  void	
  -­‐>	
  T
	
  	
  	
  	
  //	
  throws	
  Exception
}

interface	
  IObserver<in	
  T>
{
	
  	
  	
  	
  void	
  OnCompleted(bool	
  done);	
  //	
  bool	
  -­‐>	
  void
	
  	
  	
  	
  T	
  Current	
  {	
  set;	
  }	
  //	
  T	
  -­‐>	
  void
	
  	
  	
  	
  void	
  OnError(Exception	
  ex);	
  //	
  accepts	
  Exception
}
Observable Collections

interface	
  IObservable<out	
  T>
{
	
  	
  	
  	
  IDisposable	
  Subscribe(IObserver<T>	
  o)
}

interface	
  IObserver<in	
  T>
{
	
  	
  	
  	
  void	
  OnCompleted();
	
  	
  	
  	
  void	
  OnNext(T	
  item);
	
  	
  	
  	
  void	
  OnError(Exception	
  ex);
}
1
                                        Observer
                      Subscribe(o)


                      2

                  OnNext(e)
                                                3
                                OnCompleted()


  Producer pushes
successive elements                         X
from the collection
IEnumerable & IEnumerator are
prototypical interfaces for interactive
collections and interactive programs.

IObservable & IObserver are
prototypical interfaces for observable
collections and reactive, asynchronous
& event-based programs.
Iterator




Observer
Iterator / Observer
                 Patterns in Java
interface	
  Iterable<T>	
  {                class	
  Observable	
  {
	
  	
  	
  	
  Iterator<T>	
  iterator();   	
  	
  	
  	
  void	
  addObserver(Observer	
  o);
}
                                             	
  	
  	
  	
  void	
  deleteObserver(Observer	
  o);
                                             	
  	
  	
  	
  void	
  deleteObservers();
                                             	
  	
  	
  	
  int	
  countObservers();
                                             	
  	
  	
  	
  void	
  notifyObservers();
                                             	
  	
  	
  	
  void	
  notifyObservers(Object	
  arg);
                                             	
  	
  	
  	
  void	
  setChanged();
                                             	
  	
  	
  	
  void	
  clearChanged();
                                             	
  	
  	
  	
  boolean	
  hasChanged();
                                             }

interface	
  Iterator<T>	
  {                interface	
  Observer	
  {
	
  	
  	
  	
  T	
  next();                 	
  	
  	
  	
  void	
  update(Observable	
  o,	
  Object	
  arg);
                                             }
	
  	
  	
  	
  boolean	
  hasNext();
	
  	
  	
  	
  void	
  remove();
}
LINQ to Observable
LINQ to Observable

    If you are writing
 LINQ or declarative code
in an interactive program...
LINQ to Observable

    If you are writing
 LINQ or declarative code
in an interactive program...

You already know how to use it!
... the principle we go by is, don't
expect to see a particular
concurrency model put into C#
because there're many different
concurrency model ... it's more
about finding things are common
to to all kinds of concurrency ...

                - Anders Hejlsberg
... the principle we go by is, don't
expect to see a particular
concurrency model put into C#
because there're many different
concurrency model ... it's more
about finding things are common
to to all kinds of concurrency ...

                - Anders Hejlsberg
LINQ to Object
Standard query operators
  Select
  Where
  SelectMany
  ...

Extended query operators
  Zip
  Aggregate
  ...
LINQ to Observable
Standard query operators
  Select
  Where
  SelectMany
  ...

Extended query operators
  Zip
  Throttle
  ...
How to move a ball by
 keyboard (ASDW)?
Imperative Impl.
void	
  OnKeyPress(object	
  sender,	
  KeyPressEventArgs	
  e)
{
	
  	
  	
  	
  if	
  (isPlaying)
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (e.KeyChar	
  ==	
  'a'	
  &&	
  ball.Left	
  >	
  0)
	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ball.Left	
  -­‐=	
  5;
	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  	
  	
  	
  	
  else	
  if	
  (e.KeyChar	
  ==	
  'w'	
  &&	
  ball.Top	
  >	
  0)
	
  	
  	
  	
  	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ball.Top	
  -­‐=	
  5;
	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  	
  	
  	
  	
  else	
  ...
	
  	
  	
  	
  }
	
  	
  	
  	
  else	
  ...
}
Declarative Impl.
//	
  filter	
  the	
  KeyPress	
  events	
  when	
  playing
var	
  keyPress	
  =	
  GetKeyPress().Where(_	
  =>	
  isPlaying);

//	
  filter	
  the	
  events	
  to	
  move	
  left
var	
  moveLeft	
  =	
  from	
  ev	
  in	
  keyPress
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  where	
  ev.EventArgs.KeyChar	
  ==	
  'a'
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  where	
  ball.Left	
  >	
  0
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  select	
  ev;
moveLeft.Subscribe(_	
  =>	
  ball.Left	
  -­‐=	
  5);

//	
  filter	
  the	
  events	
  to	
  move	
  top
var	
  moveTop	
  =	
  from	
  ev	
  in	
  keyPress
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  where	
  ev.EventArgs.KeyChar	
  ==	
  'w'
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  where	
  ball.Top	
  >	
  0
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  select	
  ev;
moveTop.Subscribe(_	
  =>	
  ball.Top	
  -­‐=	
  5);
Mouse drag and draw
var	
  mouseMove	
  =	
  GetMouseMove();
var	
  mouseDiff	
  =	
  mouseMove.Zip(mouseMove.Skip(1),
	
  	
  	
  	
  (prev,	
  curr)	
  =>	
  new
	
  	
  	
  	
  {
	
  	
  	
  	
  	
  	
  	
  	
  PrevPos	
  =	
  new	
  Point(
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  prev.EventArgs.X,	
  prev.EventArgs.Y),
	
  	
  	
  	
  	
  	
  	
  	
  CurrPos	
  =	
  new	
  Point(
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  curr.EventArgs.X,	
  curr.EventArgs.Y)
	
  	
  	
  	
  });

var	
  mouseDrag	
  =	
  from	
  _	
  in	
  GetMouseDown()
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  from	
  diff	
  in	
  mouseDiff.TakeUntil(GetMouseUp())
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  select	
  diff;

mouseDrag.Subscribe(d	
  =>	
  DrawLine(d.PrevPos,	
  d.CurrPos));
Everything in Web is
   Asynchronous

User actions

AJAX requests

Animations

...
Reactive Framework in
      JavaScript
A full featured port for JavaScript
  Easy-to-use conversions from existing DOM,
  XmlHttpRequest, etc
  In a download size of less than 7kb (gzipped)

Bindings for various libraries / frameworks
  jQuery
  MooTools
  Dojo
  ...
Mouse drag and draw
   in JavaScript
var	
  target	
  =	
  $("#paintPad");
var	
  mouseMove	
  =	
  target.toObservable("mousemove");
var	
  mouseDiff	
  =	
  mouseMove.Zip(mouseMove.Skip(1),	
  
	
  	
  	
  	
  function(prev,	
  curr)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  return	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  prevPos:	
  {	
  x:	
  prev.clientX,	
  y:	
  prev.clientY	
  },
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  currPos:	
  {	
  x:	
  curr.clientX,	
  y:	
  curr.clientY	
  }
	
  	
  	
  	
  	
  	
  	
  	
  };
	
  	
  	
  	
  });

var	
  mouseDown	
  =	
  target.toObservable("mousedown");
var	
  mouseUp	
  =	
  target.toObservable("mouseup");
var	
  mouseDrag	
  =	
  mouseDown.SelectMany(function()	
  {
	
  	
  	
  	
  mouseDiff.TakeUntil(mouseUp);
});

mouseDrag.Subscribe(
	
  	
  	
  	
  function(d)	
  {	
  drawLine(d.prevPos,	
  d.currPos);	
  });
Wikipedia lookup
var	
  textBox	
  =	
  $("#searchInput");
var	
  searcher	
  =	
  textBox
	
  	
  	
  	
  .toObservable("keyup")
	
  	
  	
  	
  .Throttle(500)
	
  	
  	
  	
  .Select(function(_)	
  {	
  return	
  textBox.val();	
  })
	
  	
  	
  	
  .Select(function(term)	
  {	
  return	
  queryWikipedia(term);	
  })
	
  	
  	
  	
  .Switch();

searcher.Subscribe(
	
  	
  	
  	
  function(data)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  var	
  results	
  =	
  $("#results");
	
  	
  	
  	
  	
  	
  	
  	
  results.empty();
	
  	
  	
  	
  	
  	
  	
  	
  $.each(data,	
  function(_,	
  value)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  results.append($("<li/>").text(value));
	
  	
  	
  	
  	
  	
  	
  	
  });
	
  	
  	
  	
  },
	
  	
  	
  	
  function(error)	
  {	
  $("#error").html(error);	
  });
Time flies like an arrow
var	
  container	
  =	
  $("#container");
var	
  mouseMove	
  =	
  container.toObservable("mousemove");

for	
  (var	
  i	
  =	
  0;	
  i	
  <	
  text.length;	
  i++)	
  {
	
  	
  	
  	
  (function(i)	
  {

	
  	
  	
  	
  	
  	
  	
  	
  var	
  ele	
  =	
  $("<span/>").text(text.charAt(i));
	
  	
  	
  	
  	
  	
  	
  	
  ele.css({position:	
  "absolute"}).appendTo(container);

	
  	
  	
  	
  	
  	
  	
  	
  mouseMove.Delay(i	
  *	
  100).Subscribe(function	
  (ev)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ele.css({
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  left:	
  ev.clientX	
  +	
  i	
  *	
  20	
  +	
  15	
  +	
  "px",
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  top:	
  ev.clientY	
  +	
  "px"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  });
	
  	
  	
  	
  	
  	
  	
  	
  });

	
  	
  	
  	
  })(i);
Benefits of Rx

Easy to composite and coordinate async
operations

Easy to express the algorithm (code locality)

Easy to be unit tested

...
Rx & Language Features
 Features in C# that Rx uses
   Extension method
   Lambda expression & closure
   Type inference
   LINQ query expression

 Rx has been implemented in ...
   C# & VB
   JavaScript
   F#
Port to other Languages

 Rx can be easily ported to various languages
   Scala
   Ruby
   Python
   modern languages with basic functional features

 Almost impossible to implement Rx in Java
   Cannot extend a type without breaking code
   Missing enough functional features
Resources

Matthew Podwysocki
  http://codebetter.com/blogs/matthew.podwysocki/

Reactive Framework on MSDN DevLabs
  http://msdn.microsoft.com/en-us/devlabs/
  ee794896.aspx

Tomáš Petříček
  http://tomasp.net/
Q&A

More Related Content

What's hot

LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기Wanbok Choi
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoThe Software House
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming heroThe Software House
 
Building fast interpreters in Rust
Building fast interpreters in RustBuilding fast interpreters in Rust
Building fast interpreters in RustIngvar Stepanyan
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能についてUehara Junji
 
Swift internals
Swift internalsSwift internals
Swift internalsJung Kim
 
RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017Wanbok Choi
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185Mahmoud Samir Fayed
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Apache PIG - User Defined Functions
Apache PIG - User Defined FunctionsApache PIG - User Defined Functions
Apache PIG - User Defined FunctionsChristoph Bauer
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 

What's hot (20)

LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Building fast interpreters in Rust
Building fast interpreters in RustBuilding fast interpreters in Rust
Building fast interpreters in Rust
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
Swift internals
Swift internalsSwift internals
Swift internals
 
RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Apache PIG - User Defined Functions
Apache PIG - User Defined FunctionsApache PIG - User Defined Functions
Apache PIG - User Defined Functions
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Intro to Pig UDF
Intro to Pig UDFIntro to Pig UDF
Intro to Pig UDF
 
ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 

Similar to 响应式编程及框架

rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...GeeksLab Odessa
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
RxJava for Android - GDG DevFest Ukraine 2015
RxJava for Android - GDG DevFest Ukraine 2015RxJava for Android - GDG DevFest Ukraine 2015
RxJava for Android - GDG DevFest Ukraine 2015Constantine Mars
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗Pofat Tseng
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
 
Introduction to RxJava on Android
Introduction to RxJava on AndroidIntroduction to RxJava on Android
Introduction to RxJava on AndroidChris Arriola
 
Reactive computing
Reactive computingReactive computing
Reactive computingStan Lea
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUIkiahiska
 
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn TớiTech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn TớiNexus FrontierTech
 
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...Codemotion
 

Similar to 响应式编程及框架 (20)

Rxjs kyivjs 2015
Rxjs kyivjs 2015Rxjs kyivjs 2015
Rxjs kyivjs 2015
 
rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
 
Reactive x
Reactive xReactive x
Reactive x
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
RxJava for Android - GDG DevFest Ukraine 2015
RxJava for Android - GDG DevFest Ukraine 2015RxJava for Android - GDG DevFest Ukraine 2015
RxJava for Android - GDG DevFest Ukraine 2015
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Rx – reactive extensions
Rx – reactive extensionsRx – reactive extensions
Rx – reactive extensions
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Introduction to RxJava on Android
Introduction to RxJava on AndroidIntroduction to RxJava on Android
Introduction to RxJava on Android
 
Reactive computing
Reactive computingReactive computing
Reactive computing
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
 
Reacting with ReactiveUI
Reacting with ReactiveUIReacting with ReactiveUI
Reacting with ReactiveUI
 
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn TớiTech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
Tech Talk #4 : RxJava and Using RxJava in MVP - Dương Văn Tới
 
Day 1
Day 1Day 1
Day 1
 
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
 
Saving lives with rx java
Saving lives with rx javaSaving lives with rx java
Saving lives with rx java
 

More from jeffz

Wind.js无障碍调试与排错
Wind.js无障碍调试与排错Wind.js无障碍调试与排错
Wind.js无障碍调试与排错jeffz
 
JavaScript现代化排错实践
JavaScript现代化排错实践JavaScript现代化排错实践
JavaScript现代化排错实践jeffz
 
Jscex:案例、阻碍、体会、展望
Jscex:案例、阻碍、体会、展望Jscex:案例、阻碍、体会、展望
Jscex:案例、阻碍、体会、展望jeffz
 
Jscex:案例、经验、阻碍、展望
Jscex:案例、经验、阻碍、展望Jscex:案例、经验、阻碍、展望
Jscex:案例、经验、阻碍、展望jeffz
 
The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)jeffz
 
Mono for .NET Developers
Mono for .NET DevelopersMono for .NET Developers
Mono for .NET Developersjeffz
 
单点登录解决方案的架构与实现
单点登录解决方案的架构与实现单点登录解决方案的架构与实现
单点登录解决方案的架构与实现jeffz
 
Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程jeffz
 
Windows Phone应用开发心得
Windows Phone应用开发心得Windows Phone应用开发心得
Windows Phone应用开发心得jeffz
 
分布式版本管理
分布式版本管理分布式版本管理
分布式版本管理jeffz
 
使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架jeffz
 
针对iPad平台的高性能网站架构
针对iPad平台的高性能网站架构针对iPad平台的高性能网站架构
针对iPad平台的高性能网站架构jeffz
 
企业开发领域的语言特性
企业开发领域的语言特性企业开发领域的语言特性
企业开发领域的语言特性jeffz
 
大话程序员可用的算法
大话程序员可用的算法大话程序员可用的算法
大话程序员可用的算法jeffz
 
面向对象与生活
面向对象与生活面向对象与生活
面向对象与生活jeffz
 
Windows内核技术介绍
Windows内核技术介绍Windows内核技术介绍
Windows内核技术介绍jeffz
 
F#语言对异步程序设计的支持
F#语言对异步程序设计的支持F#语言对异步程序设计的支持
F#语言对异步程序设计的支持jeffz
 
大众点评网的技术变迁之路
大众点评网的技术变迁之路大众点评网的技术变迁之路
大众点评网的技术变迁之路jeffz
 
Better Framework Better Life
Better Framework Better LifeBetter Framework Better Life
Better Framework Better Lifejeffz
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 

More from jeffz (20)

Wind.js无障碍调试与排错
Wind.js无障碍调试与排错Wind.js无障碍调试与排错
Wind.js无障碍调试与排错
 
JavaScript现代化排错实践
JavaScript现代化排错实践JavaScript现代化排错实践
JavaScript现代化排错实践
 
Jscex:案例、阻碍、体会、展望
Jscex:案例、阻碍、体会、展望Jscex:案例、阻碍、体会、展望
Jscex:案例、阻碍、体会、展望
 
Jscex:案例、经验、阻碍、展望
Jscex:案例、经验、阻碍、展望Jscex:案例、经验、阻碍、展望
Jscex:案例、经验、阻碍、展望
 
The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)
 
Mono for .NET Developers
Mono for .NET DevelopersMono for .NET Developers
Mono for .NET Developers
 
单点登录解决方案的架构与实现
单点登录解决方案的架构与实现单点登录解决方案的架构与实现
单点登录解决方案的架构与实现
 
Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程Documentation Insight技术架构与开发历程
Documentation Insight技术架构与开发历程
 
Windows Phone应用开发心得
Windows Phone应用开发心得Windows Phone应用开发心得
Windows Phone应用开发心得
 
分布式版本管理
分布式版本管理分布式版本管理
分布式版本管理
 
使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架
 
针对iPad平台的高性能网站架构
针对iPad平台的高性能网站架构针对iPad平台的高性能网站架构
针对iPad平台的高性能网站架构
 
企业开发领域的语言特性
企业开发领域的语言特性企业开发领域的语言特性
企业开发领域的语言特性
 
大话程序员可用的算法
大话程序员可用的算法大话程序员可用的算法
大话程序员可用的算法
 
面向对象与生活
面向对象与生活面向对象与生活
面向对象与生活
 
Windows内核技术介绍
Windows内核技术介绍Windows内核技术介绍
Windows内核技术介绍
 
F#语言对异步程序设计的支持
F#语言对异步程序设计的支持F#语言对异步程序设计的支持
F#语言对异步程序设计的支持
 
大众点评网的技术变迁之路
大众点评网的技术变迁之路大众点评网的技术变迁之路
大众点评网的技术变迁之路
 
Better Framework Better Life
Better Framework Better LifeBetter Framework Better Life
Better Framework Better Life
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

响应式编程及框架

  • 1. Reactive Programming and Framework Zhao Jie - SNDA - Sep. 2010
  • 2. About me / / Jeffrey Zhao / Blog: http://blog.zhaojie.me/ Twitter: @jeffz_cn F#, Scala, JavaScript, Python, .NET, mono... Java (as the language) hater
  • 3. What? Fundamentally change the way you think about coordinating and orchestrating asynchronous and event-based programming
  • 4. Why? Because the essence of Cloud, Web, Mobile is asynchronous computations
  • 5. How? By showing that asynchronous and event-base computations are just push-based collections
  • 7. a := b + c
  • 8. Interactive Reactive Environment Program
  • 9. Let’s implement both interfaces with...
  • 10.
  • 11. Enumerable Collections interface  IEnumerable<out  T> {        IEnumerator<T>  GetEnumerator(); } interface  IEnumerator<out  T> {        bool  MoveNext();        T  Current  {  get;  } }
  • 12. 1 Enumerator GetEnumerator() Current 3 2 MoveNext() Consumer pulls successive elements true/false from the collection
  • 13. Dualize Enumerable Collections interface  IEnumerable<out  T> {        //  void  -­‐>  enumerator        IEnumerator<T>  GetEnumerator(); } interface  IObservable<out  T> {        //  observer  -­‐>  void        IDisposable  Subscribe(IObserver<T>  o) }
  • 14. Dualize Enumerable Collections interface  IEnumerator<out  T> {        bool  MoveNext();  //  void  -­‐>  bool        T  Current  {  get;  }  //  void  -­‐>  T        //  throws  Exception } interface  IObserver<in  T> {        void  OnCompleted(bool  done);  //  bool  -­‐>  void        T  Current  {  set;  }  //  T  -­‐>  void        void  OnError(Exception  ex);  //  accepts  Exception }
  • 15. Observable Collections interface  IObservable<out  T> {        IDisposable  Subscribe(IObserver<T>  o) } interface  IObserver<in  T> {        void  OnCompleted();        void  OnNext(T  item);        void  OnError(Exception  ex); }
  • 16. 1 Observer Subscribe(o) 2 OnNext(e) 3 OnCompleted() Producer pushes successive elements X from the collection
  • 17. IEnumerable & IEnumerator are prototypical interfaces for interactive collections and interactive programs. IObservable & IObserver are prototypical interfaces for observable collections and reactive, asynchronous & event-based programs.
  • 19. Iterator / Observer Patterns in Java interface  Iterable<T>  { class  Observable  {        Iterator<T>  iterator();        void  addObserver(Observer  o); }        void  deleteObserver(Observer  o);        void  deleteObservers();        int  countObservers();        void  notifyObservers();        void  notifyObservers(Object  arg);        void  setChanged();        void  clearChanged();        boolean  hasChanged(); } interface  Iterator<T>  { interface  Observer  {        T  next();        void  update(Observable  o,  Object  arg); }        boolean  hasNext();        void  remove(); }
  • 21. LINQ to Observable If you are writing LINQ or declarative code in an interactive program...
  • 22. LINQ to Observable If you are writing LINQ or declarative code in an interactive program... You already know how to use it!
  • 23. ... the principle we go by is, don't expect to see a particular concurrency model put into C# because there're many different concurrency model ... it's more about finding things are common to to all kinds of concurrency ... - Anders Hejlsberg
  • 24. ... the principle we go by is, don't expect to see a particular concurrency model put into C# because there're many different concurrency model ... it's more about finding things are common to to all kinds of concurrency ... - Anders Hejlsberg
  • 25. LINQ to Object Standard query operators Select Where SelectMany ... Extended query operators Zip Aggregate ...
  • 26. LINQ to Observable Standard query operators Select Where SelectMany ... Extended query operators Zip Throttle ...
  • 27. How to move a ball by keyboard (ASDW)?
  • 28. Imperative Impl. void  OnKeyPress(object  sender,  KeyPressEventArgs  e) {        if  (isPlaying)        {                if  (e.KeyChar  ==  'a'  &&  ball.Left  >  0)                {                        ball.Left  -­‐=  5;                }                else  if  (e.KeyChar  ==  'w'  &&  ball.Top  >  0)                {                        ball.Top  -­‐=  5;                }                else  ...        }        else  ... }
  • 29. Declarative Impl. //  filter  the  KeyPress  events  when  playing var  keyPress  =  GetKeyPress().Where(_  =>  isPlaying); //  filter  the  events  to  move  left var  moveLeft  =  from  ev  in  keyPress                              where  ev.EventArgs.KeyChar  ==  'a'                              where  ball.Left  >  0                              select  ev; moveLeft.Subscribe(_  =>  ball.Left  -­‐=  5); //  filter  the  events  to  move  top var  moveTop  =  from  ev  in  keyPress                            where  ev.EventArgs.KeyChar  ==  'w'                            where  ball.Top  >  0                            select  ev; moveTop.Subscribe(_  =>  ball.Top  -­‐=  5);
  • 31. var  mouseMove  =  GetMouseMove(); var  mouseDiff  =  mouseMove.Zip(mouseMove.Skip(1),        (prev,  curr)  =>  new        {                PrevPos  =  new  Point(                        prev.EventArgs.X,  prev.EventArgs.Y),                CurrPos  =  new  Point(                        curr.EventArgs.X,  curr.EventArgs.Y)        }); var  mouseDrag  =  from  _  in  GetMouseDown()                                from  diff  in  mouseDiff.TakeUntil(GetMouseUp())                                select  diff; mouseDrag.Subscribe(d  =>  DrawLine(d.PrevPos,  d.CurrPos));
  • 32. Everything in Web is Asynchronous User actions AJAX requests Animations ...
  • 33. Reactive Framework in JavaScript A full featured port for JavaScript Easy-to-use conversions from existing DOM, XmlHttpRequest, etc In a download size of less than 7kb (gzipped) Bindings for various libraries / frameworks jQuery MooTools Dojo ...
  • 34. Mouse drag and draw in JavaScript
  • 35. var  target  =  $("#paintPad"); var  mouseMove  =  target.toObservable("mousemove"); var  mouseDiff  =  mouseMove.Zip(mouseMove.Skip(1),          function(prev,  curr)  {                return  {                        prevPos:  {  x:  prev.clientX,  y:  prev.clientY  },                        currPos:  {  x:  curr.clientX,  y:  curr.clientY  }                };        }); var  mouseDown  =  target.toObservable("mousedown"); var  mouseUp  =  target.toObservable("mouseup"); var  mouseDrag  =  mouseDown.SelectMany(function()  {        mouseDiff.TakeUntil(mouseUp); }); mouseDrag.Subscribe(        function(d)  {  drawLine(d.prevPos,  d.currPos);  });
  • 37. var  textBox  =  $("#searchInput"); var  searcher  =  textBox        .toObservable("keyup")        .Throttle(500)        .Select(function(_)  {  return  textBox.val();  })        .Select(function(term)  {  return  queryWikipedia(term);  })        .Switch(); searcher.Subscribe(        function(data)  {                var  results  =  $("#results");                results.empty();                $.each(data,  function(_,  value)  {                        results.append($("<li/>").text(value));                });        },        function(error)  {  $("#error").html(error);  });
  • 38. Time flies like an arrow
  • 39. var  container  =  $("#container"); var  mouseMove  =  container.toObservable("mousemove"); for  (var  i  =  0;  i  <  text.length;  i++)  {        (function(i)  {                var  ele  =  $("<span/>").text(text.charAt(i));                ele.css({position:  "absolute"}).appendTo(container);                mouseMove.Delay(i  *  100).Subscribe(function  (ev)  {                        ele.css({                                left:  ev.clientX  +  i  *  20  +  15  +  "px",                                top:  ev.clientY  +  "px"                        });                });        })(i);
  • 40. Benefits of Rx Easy to composite and coordinate async operations Easy to express the algorithm (code locality) Easy to be unit tested ...
  • 41. Rx & Language Features Features in C# that Rx uses Extension method Lambda expression & closure Type inference LINQ query expression Rx has been implemented in ... C# & VB JavaScript F#
  • 42. Port to other Languages Rx can be easily ported to various languages Scala Ruby Python modern languages with basic functional features Almost impossible to implement Rx in Java Cannot extend a type without breaking code Missing enough functional features
  • 43. Resources Matthew Podwysocki http://codebetter.com/blogs/matthew.podwysocki/ Reactive Framework on MSDN DevLabs http://msdn.microsoft.com/en-us/devlabs/ ee794896.aspx Tomáš Petříček http://tomasp.net/
  • 44. Q&A