4. Is Rx (Reactive Extensions) right for me?
Rx (Rx.NET)
RxJs
Bacon.JS
Ruby
RxJava
RxCpp
Python
ReactiveCocoa
reactivex.io
rxmarbles.com
introtorx.com
The introduction to Reactive
Programming you've been
missing
Paul Betts - Introduction to
Rx
reactiveui.readthedocs.org
GitHub
NetFlix
Microsoft
7. REACTIVE
Reactive programming is an emerging
discipline which combines concurrency
and event-based and asynchronous
systems.
- Wikipedia
8. REACTIVE
Reactive programming is programming
with asynchronous data streams.
- staltz
TODO: Drink some water
Get example of async data streams from audience
11. FUNCTIONAL
‘First Class’ Functions
Pass functions into function
Declarative Programming
Compose methods together to create higher abstraction
FRP uses come functional concepts but not all. FRP can be an introduction into functional
programming.
C# has functional concepts but is not a functional language.
12. FUNCTIONAL
var even = numberRepository()
.Select(x => x + 1)
.Where(x => x % 2 == 0)
.OrderByDescending(x=>x);
linq is functional in nature
pass functions into ‘functions’ operators
methods can be composed
13. FUNCTIONAL
‘First Class’ Functions
Pass functions into function
Declarative Programming
Compose methods together to create higher abstraction
Immutable Data
We don’t change data, we project (select) it into new formats
FRP only really uses a small subset of functional concepts. The reactive part of FRP is more more
complex and mind bending.
14. REACTIVE
Reactive programming is programming
with asynchronous data streams.
- staltz
TODO: Drink some water
Get example of async data streams from audience
15. REACTIVE
Click
Click: async - if it happens, it will happen in the future.
Examples of async data streams: click, message queue, mouse move.
FRP is CONSTRUCTS for programming with async data streams.
17. REACTIVE
twitter feed
directory
searching
web service calls
keyboard input
file changed
Twitter feed as data stream
When you start thinking about async data streams.
EVERYTHING BECOMES AN ASYNC DATA STREAM!
list scroll
video processing
mouse move
queues
messaging
19. REACTIVE
IObservable<T> and IObserver<T>
Sometime, in the future, someone is going to give me data, how do I reason about it
IEnumerable<T> and IEnumerable<T>
I want all the data now! or I’ll stand here and wait, no one can do anything until I get my
data!
20. REACTIVE
IObservable<T> and IObserver<T>
Sometime, in the future, someone is going to give me data, how do I reason about it
IEnumerable<T> and IEnumerable<T>
I want all the data now! or I’ll stand here and wait, no one can do anything until I get my
data!
23. REACTIVE
Reactive programming is turning
everything into an asynchronous data
stream and programming with
asynchronous data streams.
- Eric Polerecky aka: detroitpro
TODO: Drink some water
Get example of async data streams from audience
28. Let’s talk about declarative programming
var even = numberRepository()
.Select(x => x + 1)
.Where(x => x % 2 == 0)
.OrderByDescending(x=>x);
29. “
Expresses the logic of a
computation without describing its
control flow
=
Declarative Programming
30. What is a monad?
MyObservable //event args come in, I don’t care from where
.Select(x => x.FullPath) //transform data stream
.Do(ZipFile) //the business logic that needs to happen
.Catch<string,Exception>(...)
.Retry(3) //cross cutting concerns removed from logic
.Buffer(2) //bend time and space
.Subscribe(); //make it so
37. Let’s review what we learned about FRP
■ Reverse the flow of data
■ Declarative (higher level abstraction)
■ Linq to events
■ Good for when you would work with events
■ Good for when you have state (not request-response)
■ Reactive libraries are available in every language
■ Rx is on nuget (Rx-Main)
FRP is not pure functional programming.
Functional programming in C# is not pure functional programming.
Show a directory searcher with retry and junk.
https://gist.github.com/detroitpro/204b9874c07817fd2bea
Pass functions into functions
Compose/chain functions
Pass functions into functions
Compose/chain functions
Pass functions into functions
Compose/chain functions
Show a directory searcher with retry and junk.
https://gist.github.com/detroitpro/204b9874c07817fd2bea
focused on describing how a program operates.
HTML (and XAML) is an example of declarative programming, we describe what we want, the rendering engine is responsible for display/layout.
We reverse the flow of the caller, decouple the side-effects
We build up a linq query, but nothing happens until the console.writeline. If we remove the foreach and console.writeline no items are pulled out of the enumerable.range.
This (building up monads) is a concept from functional programming.
This (passing lambdas) is also a concept from functional programming.
GetEnumerator is called on the list of items until it is complete.
What we have here is a pull based system.
Our programming is pulling items out of the list, filtering on them (that’s cool) and acting on some of them.