Rx is a library for composing asynchronous and event-based programs using observable collections.

Similar documents
Rx: Curing your Asynchronous Programming Blues Bart J.F. De Smet

LINQ, Take Two Realizing the LINQ to Everything Dream. Bart J.F. De Smet Software Development Engineer

Erik Meijer Wes Dyer Jeffrey van Gogh Bart de Smet Matthew Podwysocki

VS08 This One Goes to Going Parallel with PFX, PLINQ, TPL and Async Keywords

Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

MEAP Edition Manning Early Access Program Rx.NET in Action Version 11

C# s A Doddle. Steve Love. ACCU April 2013

How to be a C# ninja in 10 easy steps. Benjamin Day

Course Hours

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

SAMPLE CHAPTER. Tamir Dresher. FOREWORD BY Erik Meijer MANNING

10266 Programming in C Sharp with Microsoft Visual Studio 2010

Computation at the Speed of Monads July Computation at the Speed of Monads. Brigham Young University - Idaho.

C# in Depth THIRD EDITION

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

Learn to Love Lambdas

LinQ Why we have to teach functional programmming

Programming in C# with Microsoft Visual Studio 2010

9 A Preview of.net 2.0

Reactive programming: origins & ecosystem. Jonas Chapuis, Ph.D.

C # 7, 8, and beyond: language features from design to release to IDE support. Kevin

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007

Programming in Visual Basic with Microsoft Visual Studio 2010

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

Microsoft. Microsoft Visual C# Step by Step. John Sharp

BE PROACTIVE USE REACTIVE

Functional programming in C#

Microsoft Visual C# Step by Step. John Sharp

C# in Depth SECOND EDITION JON SKEET. MANNING Greenwich (74 w. long.)

Reactive Programming in Java. Copyright - Syncogni Consulting Pvt Ltd. All rights reserved.

Hands-On Lab. Lab Manual ILL-054 Creating and Using Iterators in the.net Framework

Applied object oriented programming. 4 th lecture

Learn to Love Lambdas

Spring MVC 4.x Spring 5 Web Reactive

Concurrency: An Overview

Reactive Programming in Java. Copyright - Syncogni Consulting Pvt Ltd. All rights reserved.

MSSQL and.net. Using SQL in.net, running.net code in SQL Server

C# Asynchronous Programming Model

Why do you want to know about functional programming?

Objectives. Introduce static keyword examine syntax describe common uses

C# Programming. Unit 1: Introducing C# and the.net FrameworkThis module explains the.net Framework, and using C# and

UI-Testing, Reactive Programming and some Kotlin.

Asynchronous Functions in C#

DOT NET SYLLABUS FOR 6 MONTHS

Asset tracking: Monitoring high-value mobile assets like locomotives, marine vessels and industrial equipment. Condition based Maintenance.

C# COMO VOCÊ (TALVEZ) NUNCA VIU

Advanced Programming C# Lecture 13. dr inż. Małgorzata Janik

Index. Cambridge University Press Functional Programming Using F# Michael R. Hansen and Hans Rischel. Index.

CHAPTER 1: INTRODUCING C# 3

Programming in C#

DOT NET Syllabus (6 Months)

.NET Database Technologies. Entity Framework: Queries and Transactions

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

OptiQL: LINQ on Delite

LINQ Language-Integrated Query Introduction

RxJava. and WHY you should care. Jeroen Tietema

1 de :02

Reaktive Anwendungen mit RxJava. Dr. Michael Menzel

Repository Pattern and Unit of Work with Entity Framework

Lecture 21 Concurrent Programming

20483BC: Programming in C#

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

An Introduction to What s Available in.net 4.0 PARALLEL PROGRAMMING ON THE.NET PLATFORM

Edulinq: Reimplementing LINQ to Objects

Seminar 11 week 11 (11-15 December 2017)

Bart De Smet C# 4.0 UNLEASHED

Advanced Programming C# Lecture 12. dr inż. Małgorzata Janik

The course introduces many of the techniques and technologies employed by modern desktop and enterprise applications, including:

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios

This module reviews the core syntax and features of the C# programming language. It also provides an introduction to the Visual Studio 2012 debugger.

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści

Course Description. Audience. Module Title : 20483B: Programming in C# Duration : 5 days. Course Outline :: 20483B ::

The next section discusses when and how to design abstractions that might or might not support some features.

A modern programming language focused on integration

Functions & First Class Function Values

Asynchronous Programming - Done right

Programming with the Service Control Engine Subscriber Application Programming Interface

EEE-425 Programming Languages (2013) 1

Advanced C# Delegates.

STARCOUNTER. Technical Overview

The results for a few specific cases below are indicated. allequal ([1,1,1,1]) should return true allequal ([1,1,2,1]) should return false

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Advanced Programming C# Lecture 10. dr inż. Małgorzata Janik

What s new in ASP.NET 3.5? Mike Ormond Developer & Platform Group Microsoft Ltd

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

Threads are lightweight processes responsible for multitasking within a single application.

Multithreading and Interactive Programs

Multiple processes can run in parallel on a single computer and multiple threads can run in parallel in a single process.

Programming in C# (20483)

Introduce C# as Object Oriented programming language. Explain, tokens,

Reactive Programming with Vert.x

System.Collections.Generic.SortedSet: who needs another collection anyway?

20-CS Programming Languages Fall 2018

Visual C# 2012 How to Program by Pe ars on Ed uc ati on, Inc. All Ri ght s Re ser ve d.

Today. Continue our very basic intro to JavaScript. Lambda calculus

Programming in C# for Experienced Programmers

Comprehensive Angular 2 Review of Day 3

CS 6112 (Fall 2011) Foundations of Concurrency

Programming with the Service Control Engine Subscriber Application Programming Interface

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Transcription:

bartde@microsoft.com Slides license: Creative Commons Attribution Non-Commercial Share Alike See http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode

Too hard today (f g)(x) = f(g(x)) Rx is a library for composing asynchronous and event-based programs using observable collections. Queries? LINQ? MSDN DevLabs.NET 3.5 SP1,.NET 4.0 Silverlight 3, Silverlight 4 JavaScript (RxJS) XNA 3.1 for XBOX and Zune Windows Phone 7

interface IEnumerable out IEnumerator Get C# 4.0 covariance interface IEnumerator out IDisposable bool void Move get You could get stuck

(Waiting to move next) C# 4.0 covariance moving on You could get stuck

Because the Dutch are (said to be) cheap A B A B A B A B

Because the Dutch are (said to be) cheap A B A B A B A B

The recipe to dualization http://en.wikipedia.org/wiki/dual_(category_theory) Making a U-turn in synchrony Reversing arrows Input becomes output and vice versa

interface IEnumerable IEnumerator interface IEnumerator IDisposable bool void get

interface IEnumerable IEnumerator void interface IEnumerator IDisposable bool void void throws Exception get void C# didn t borrow Java checked exceptions

interface IEnumerable<T> IEnumerator<T> GetEnumerator(void); interface IEnumerator IDisposable bool void throws Exception void

interface IEnumerable<T> (IDisposable & IEnumerator<T>) GetEnumerator(void); interface IEnumerator We really got an enumerator and a disposable bool void throws Exception void

interface IEnumerable<T> IDisposable IEnumerator<T> ) GetEnumerator( void interface IEnumerator Will only dualize the synchrony aspect bool void throws Exception void

interface IEnumerableDual<T> Set IDisposable void IEnumerator interface IEnumerator bool void throws Exception void

interface IEnumerableDual IDisposable IEnumerator<T> x interface IEnumerator This is an output too bool void throws Exception void

interface IEnumerableDual IDisposable IEnumerator<T> x interface IEnumerator bool Exception void void Discrete domain with true and false

interface IEnumerableDual IDisposable IEnumerator<T> x interface IEnumerator T true false Exception void void If you got true, you really got a T

interface IEnumerableDual IDisposable IEnumerator<T> x interface IEnumerator void false Exception void If you got false, you really got void

interface IEnumerableDual IDisposable IEnumerator<T> x); interface IEnumerator<T> (T void Exception) MoveNext( void

interface IEnumerableDual IDisposable IEnumeratorDual<T>); interface IEnumeratorDual<T> Got void (T void Exception)); But C# doesn t have discriminated unions Let s splat this into three methods instead!

interface IEnumerableDual IDisposable IEnumeratorDual<T> interface IEnumeratorDual void void void Exception void

interface IObservable IDisposable IObserver<T> observer interface IObserver void void void Exception Source: http://amazon.com

interface IObservable out IDisposable Do you really know C# 4.0? IObserver<T> observer Used to detach the observer interface IObserver in void void void Exception

interface IObservable out IDisposable IObserver<T> observer interface IObserver in void void void Exception (*) Visit http://en.wikipedia.org/wiki/color_of_the_bikeshed

interface IObservable out IDisposable Subscribe IObserver interface IObserver in C# 4.0 contravariance void On void On Exception void On You could get flooded

Interactive MoveNext Application Got next? IEnumerable<T> IEnumerator<T> OnNext IObservable<T> IObserver<T> Have next! Reactive Environment

OnCompleted.Empty<int>() new int[0] OnNext.Return(42) new[] { 42 } OnError.Throw<int>(ex) Throwing iterator.never<int>() Notion of time Iterator that got stuck

OnNext OnError OnCompleted.Range(0, 3) OnNext(0) OnNext(1) OnNext(2).Range(0, 3) yield 0 yield 1 yield 2

A variant with time notion exists (GenerateWithTime) Observable Hypothetical anonymous iterator syntax in C# new IEnumerable int for int yield return Asynchronous Console Synchronous foreach var in Console

IObservable int Observable int // Assume we introduce concurrency (see later) IDisposable C# 4.0 named parameter syntax Console "Next: " Console "Oops: " Console "Done" C# doesn t have anonymous interface implementation, so we provide various extension methods that take lambdas.

IObservable int Observable int // Assume we introduce concurrency (see later) IDisposable Console "Next: " Console "Oops: " Console "Done" Thread.Sleep(30000); // Main thread is blocked F10

IObservable int Observable int // Assume we introduce concurrency (see later) IDisposable Console "Next: "

IObservable int Observable int // Assume we introduce concurrency (see later) IDisposable Console "Next: " Console "Oops: " Console "Done" Thread.Sleep(30000); // Main thread is blocked F5

IObservable int Observable int // Assume we introduce concurrency (see later) Breakpoint got hit IDisposable Console "Next: " Console "Oops: " Console "Done" Thread.Sleep(30000); // Main thread is blocked

.MouseMove args if ( == ) // I d like to raise another event Lack of composition -= /* what goes here? */ Resource maintenance?

IObservable<Point> Observable.FromEvent "MouseMove" var.where( ) Can define operators var.dispose() Resource maintenance!

Exceptions? FileStream File "data.txt" byte new byte new AsyncCallback int Cancel? // Do something with bs[0..bytesread-1] null State? Lack of composition Synchronous completion?

FileStream File "data.txt" Func IObservable< > Observable.FromAsyncPattern byte new byte // Do something with bs[0..bytesread-1]

Cold.Return.Subscribe( ).Subscribe( ) Hot.FromEvent " "

IScheduler.Return Scheduler.ThreadPool

duality.toobservable();.toenumerable() reactive.amb( )

.Return Scheduler.ThreadPool " ".ObserveOn(frm) " "

push based notion of time // Producing an IObservable<Point> using Select select.location // Filtering for the first bisector using Where where

Asynchronous request React TextChanged Reaction Reactive Reactor Data binding on UI thread

// IObservable<string> from TextChanged events var Observable EventArgs "TextChanged" var from in select TextBox TimeSpan // Bridge with the dictionary web service var new DictServiceSoapClient var Observable string DictionaryWord // Compose both sources using SelectMany var from in from in select input.selectmany(term => lookup(term))

Re Rea Reac React Reactive Reacti Reactiv R Reactive Reaction Reactive Reactor input Service call 1 Service call 2 UI data binding

Re Rea Reac React Reactive Reacti Reactiv R Reactive Reaction Reactive Reactor input Service call 1 Service call 2 UI data binding Source: http://scrapetv.com

Re Rea Reac React Reactive Reacti Reactiv R Reactive Reaction Reactive Reactor input Service call 1 Service call 2 UI data binding Source: http://scrapetv.com

Re Rea Reac React Reactive Reacti Reactiv R Reactive Reaction Reactive Reactor input Service call 1 Take Until Service call 2 UI data binding Source: http://scrapetv.com

Re Rea Reac React Reactive Reacti Reactiv R Reactive input Service call 1 Service call 2 UI data binding

// IObservable<string> from TextChanged events var Observable EventArgs "TextChanged" var from in select TextBox TimeSpan // Bridge with the dictionary web service var new DictServiceSoapClient var Observable string DictionaryWord // Compose both sources using SelectMany Very local fix var from in from in.takeuntil(input) select

// IObservable<string> from TextChanged events var Observable EventArgs "TextChanged" var from in select TextBox TimeSpan // Bridge with the dictionary web service var new DictServiceSoapClient var Observable string DictionaryWord // Alternative Compose both approach sources for using composition SelectMany using: // var IObservable<T> from Switch<T>(IObservable<IObservable<T>> in sources) var res = (from term in input.takeuntil(input) select select lookup(term)) Hops from source to source.switch();

Fixed (MSIL) Homo-iconic AsQueryable AsQbservable Translatable (Expression trees) How? IQueryable<T> E.g. LINQ to SQL ToQbservable IQbservable<T> E.g. LINQ to PowerShell ToQueryable LINQ to *.* AsObservable AsEnumerable ToObservable IEnumerable<T> E.g. LINQ to Objects IObservable<T> E.g. LINQ to Events ToEnumerable Pull (interactive) Duality Push (reactive) What? Threads Worker pools Message loops Distributed

Way simpler with Rx (f g)(x) = f(g(x)) Rx is a library for composing asynchronous and event-based programs using observable collections. Queries! LINQ! MSDN DevLabs.NET 3.5 SP1,.NET 4.0 Silverlight 3, Silverlight 4 JavaScript (RxJS) XNA 3.1 for XBOX and Zune Windows Phone 7

http://blogs.msdn.com/rxteam http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx http://social.msdn.microsoft.com/forums/en-us/rx http://channel9.msdn.com/tags/rx