ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
NDC14 - Rx? Functional Reactive Programming?? ??? ?? ???
2
3
? Google
4
???? ???? ?? ?????? ?????
5
? ?
f : X ¡ú Y
int main() {
return 42;
}
a
b
c
1
2
3
X Y
f
6
a
b
c
1
2
3
X Y
f : X ¡ú Y
?
?
?
Z
g : Y ¡ú Z
f g
7
a
b
c
X
?
?
?
Z
g ¡ã f : X ¡ú Z
g ¡ã f
8
????
¡­
int y = f(x);
int z = g(y);
¡­
9
???? ????? ? ??, ????? ??? ¡ú ???, ???
f g
10
???? ?? ???? ?????
g ¡ã f
11
? ??? ??? ??? ????? ?
12
?? ?? ?? ?? ??? ???? ???? ????
ANYTHING
13
? ????? ??? ???? ??? ???!
? Google
14
???: ???? ??
15
40? ? ????
16
17
7~80??? ???? ??? ?? ??? ??? ?
???? ?? ??? ???? ?? ???? ??
18
???? ??? ????
19
? ???? ????? ??
??? ???? ??? ??
20
NDC14 - Rx? Functional Reactive Programming?? ??? ?? ???
22
A = 3
B = 4
C = A + B
A = 4
B = 5
print C
23
??? 7? ?????
24
??? ???? Reactive Programming
C = A + B
+
A
C
B
25
???? ??? ???? ??,
???? ??? ??? ???? ?
26
??? ???? ??? ??? ??
27
??? ??? ?? ??? ??
? Behringer
28
??? ?? ??? ??? ??
? Manu Cornet
29
?? ??? ?? ????
Declarative
Logic
Abductive
Answer Set
Constraint
Functional
Inductive
Functional
Functional Logic
Dataflow
Reactive
Cell-Oriented
Structured
Object-Oriented
Prototype-BasedClass-Based
ModularBlock-Structured
Point-Free Style
Procedural
Event-Driven
Service-Oriented
Time-Driven
Concurrent
Relativistic
Action
Agent-Oriented
Aspect-Oriented
Automata-Based
End-User
Expression-Oriented Feature-Oriented
Non-Structured Array
Metaprogramming
Template
Reflective
Homoiconic
Automatic
Flow-Based
Concatenative
Function-LevelValue-Level
Imperative
Semantic
Concept
ProbabilisticLanguage-Oriented
Natural Language
Discipline-Specific
Domain-Specific
Grammar-Oriented
Intentional
Programming Paradigms @ Wikipedia
Declarative
Logic
Abductive
Answer Set
Constraint
Functional
Inductive
Functional
Functional Logic
Dataflow
Reactive
Cell-Oriented
Structured
Object-Oriented
Prototype-BasedClass-Based
ModularBlock-Structured
Point-Free Style
Procedural
Event-Driven
Service-Oriented
Time-Driven
Concurrent
Relativistic
Action
Agent-Oriented
Aspect-Oriented
Automata-Based
End-User
Expression-Oriented Feature-Oriented
Non-Structured Array
Metaprogramming
Template
Reflective
Homoiconic
Automatic
Flow-Based
Concatenative
Function-LevelValue-Level
Imperative
Semantic
Concept
ProbabilisticLanguage-Oriented
Natural Language
Discipline-Specific
Domain-Specific
Grammar-Oriented
Intentional
31
¡­
mov ah, 09h
lea dx, msg
int 21h
¡­
Declarative
Logic
Abductive
Answer Set
Constraint
Functional
Inductive
Functional
Functional Logic
Dataflow
Reactive
Cell-Oriented
Structured
Object-Oriented
Prototype-BasedClass-Based
ModularBlock-Structured
Point-Free Style
Procedural
Event-Driven
Service-Oriented
Time-Driven
Concurrent
Relativistic
Action
Agent-Oriented
Aspect-Oriented
Automata-Based
End-User
Expression-Oriented Feature-Oriented
Non-Structured Array
Metaprogramming
Template
Reflective
Homoiconic
Automatic
Flow-Based
Concatenative
Function-LevelValue-Level
Imperative
Semantic
Concept
ProbabilisticLanguage-Oriented
Natural Language
Discipline-Specific
Domain-Specific
Grammar-Oriented
Intentional
32
typedef struct {
int x, y
} POINT;
void foo(POINT *p) {
if (p->x > 0) {
p->y *= -1;
}
}
Declarative
Logic
Abductive
Answer Set
Constraint
Functional
Inductive
Functional
Functional Logic
Dataflow
Reactive
Cell-Oriented
Structured
Object-Oriented
Prototype-BasedClass-Based
ModularBlock-Structured
Point-Free Style
Procedural
Event-Driven
Service-Oriented
Time-Driven
Concurrent
Relativistic
Action
Agent-Oriented
Aspect-Oriented
Automata-Based
End-User
Expression-Oriented Feature-Oriented
Non-Structured Array
Metaprogramming
Template
Reflective
Homoiconic
Automatic
Flow-Based
Concatenative
Function-LevelValue-Level
Imperative
Semantic
Concept
ProbabilisticLanguage-Oriented
Natural Language
Discipline-Specific
Domain-Specific
Grammar-Oriented
Intentional
33
template<typename T>
class Foo {
T t;
public:
Foo(T t) : t(t) {}
void foo() {
cout << t;
}
};
Declarative
Logic
Abductive
Answer Set
Constraint
Functional
Inductive
Functional
Functional Logic
Dataflow
Reactive
Cell-Oriented
Structured
Object-Oriented
Prototype-BasedClass-Based
ModularBlock-Structured
Point-Free Style
Procedural
Event-Driven
Service-Oriented
Time-Driven
Concurrent
Relativistic
Action
Agent-Oriented
Aspect-Oriented
Automata-Based
End-User
Expression-Oriented Feature-Oriented
Non-Structured Array
Metaprogramming
Template
Reflective
Homoiconic
Automatic
Flow-Based
Concatenative
Function-LevelValue-Level
Imperative
Semantic
Concept
ProbabilisticLanguage-Oriented
Natural Language
Discipline-Specific
Domain-Specific
Grammar-Oriented
Intentional
34
???
Logic
Abductive
Answer Set
Constraint
Functional
Inductive
???
Functional Logic
??????
????
Cell-Oriented
???
????
Prototype-Based??? ??
????? ??
Point-Free Style
???
Event-Driven
Service-Oriented
Time-Driven
???
Relativistic
Action
Agent-Oriented
Aspect-Oriented
Automata-Based
End-User
Expression-Oriented Feature-Oriented
Non-Structured Array
???????
???
????
Homoiconic
Automatic
Flow-Based
Concatenative
Function-LevelValue-Level
???
Semantic
Concept
ProbabilisticLanguage-Oriented
Natural Language
Discipline-Specific
Domain-Specific
Grammar-Oriented
Intentional
35
???
imperative
???
declarative
???
procedural
???
concurrent
36
???? ??? ??? ? ?
37
Event-Driven
???? ????
Scalable
??? ????
Resilient
??? ????
Responsive
???? ????
38
1?
?
?
39
10-3?
?
?
40
10-6?
?
? ???? ???
41
10-9?
?
?
42
?
?
?
?
?
?
?
?
43
?? ??!!
OUTPUT foo(INPUT a);
44
??? ????
??? ???? ??? ?? ???
???? ???? ?? ???? ???? ??
???? ????? ??? ???? ?????
?
?
?
?
?
?
?
?
45
?? ??!!
? Peter Thomas
46
???? ??? ?? ??
+ ???? JDBC? ???
47
???? ??? ????, ? ?? ???? ??? ??? ??!
48
????? ??? ???? ???? ?????
49
?? ????? ? ?? ???? ????
NDC14 - Rx? Functional Reactive Programming?? ??? ?? ???
?
?
?
?
?
?
?
51
function foo(a, callback);
52
node.js? vert.x? ???? ??
foo(a, function(err, result) {
if (err) {
// handle error
} else {
// use result
}
);
53
// ?? ?? ??
function compositeTask(t0, callback) {
task1(t0, function(err, t1) {
if (err) {
callback(err);
}
task2(t1, function(err, t2) {
if (err) {
callback(err);
}
task3(t2, function(err, t3) {
if (err) {
callback(err);
}
callback(null, t3);
});
});
});
}
54
OUTPUT foo(INPUT a);
55
?? ?? ????
M<OUTPUT> foo(INPUT a);
56
INPUT => M<OUTPUT>
INPUT => OUTPUT
57
Checkpoint!
58
59
60
? Aditya Bhargava
61
?? ?
? Aditya Bhargava
62
? ?? ??? ?? ??? ?? ?
? Aditya Bhargava
Maybe, Option, Optional, Nullable
63
?? ?? ?? ?? ??? ??
? Aditya Bhargava
64
?? ??? +3? ??? ? ????-
? Aditya Bhargava
65
????? ?? ??? ? ??!
? Aditya Bhargava
66
??? map
? Aditya Bhargava
67
?? ??? ?? ?? ?? ??
? Aditya Bhargava
68
??? ??? ? ??? ??? ? ??!
f g
69
??? ???? ????¡­
+3 +4
? Aditya Bhargava
70
? Aditya Bhargava
71
?? ??? ??? ???
72
??? ?? ???
73
74
75
76
unit, return, just mapMany, bind, thenCompose, >>=
a = unit(2)
b = a.flatMap(x -> unit(x+3))
c = b.flatMap(y -> unit(y+4))
// c == unit(9)
+3
+4
77
?? ??
?? Try<T> Iterable<T>
??? Future<T>
78
???
79
?? ??
?? Try<T> Iterable<T>
??? Future<T> Observable<T>
80
81
??? ??? ??? ?? ?? ???? ??
Rx
Reactive Extensions
(.NET, 2009)
RxJava (2012)
rxjava-scala
rxjava-groovy
rxjava-clojure
rxjava-jruby
rxjava-kotlin
RxJS
RxCPP
RxPy
(2011)
(2012)
(2013)
82
Iterable (pull) Observable (push)
??? ?? T next() onNext(T)
?? ?? throws Exception onError(Exception)
?? returns onCompleted()
83
Iterable (pull) Observable (push)
getDataFromLocalMemory()
.skip(10)
.take(5)
.map(s -> s + "foo")
.forEach(println)
getDataFromNetwork()
.skip(10)
.take(5)
.map(s -> s + "foo")
.forEach(println)
84
+3
+4
Observable<int> add(Observable<int> input)
{
return input.map(x -> x+3)
.map(y -> y+4);
}
85
query1
query2
Observable<int> query1(int input);
Observable<int> query2(int input);
Observable<int> query(Observable<int> input)
{
return input.flatMap(query1)
.flatMap(query2);
}
86
x + y
Observable<int>
zip(Observable<int> xs, Observable<int> ys)
{
return zip(xs, ys, (x, y) -> x + y);
}
yx
87
?
?
?
?
?
?
?
?
?
?
88
TCP Dispatcher
Handler
Handler
Handler
¡­
Data Grid
DB Driver
¡­
89
TCP Dispatcher
Handler
Handler
Handler
¡­
Data Grid
DB Driver
¡­
90
Node
Node 1 Node 2
Node 4Node 3
91
Node 1 Node 2
Node 4Node 3
92
Service
Service A
Service B
Service D
Service C
Service E
93
Service A
Service B
Service D
Service C
Service E
94
Service A
Service B
Service D
Service C
Service E
95
Event-Driven
???? ????
Scalable
??? ????
Resilient
??? ????
Responsive
???? ????
96
97
http://www.reactive-streams.org/
98
99
100
101
102
103
NDC14 - Rx? Functional Reactive Programming?? ??? ?? ???
105

More Related Content

NDC14 - Rx? Functional Reactive Programming?? ??? ?? ???

Editor's Notes

  1. ??????
  2. ?? ????? ? ? ?? ??? ? ????? ??? ???? ? ? ?? ????. ?? ??? ?????? ??? ?? ??? ?? ?? ??? Functional Reactive Programming ???.
  3. ?? ? ??? ¡°?? ?? ??¡±??? ????? ??? ?? ??? ?? ???? ??????? ?? ??? ??? ?? ?? ??? ???. ??? ?? ???? ????? ??????? ?? ??? ???? ?? ?????, ?? ? ????? ?? ?? ???? ??? ? ??? ?????.
  4. ?? ??? ????, ????? ????? ??? ???? ??? ???? ?? ?? ??? ????. ???? ??? ??? ???? ??? ?? ??? ???Imperative ?? ???Procedural ??? ???.
  5. ??? ??? ???? ????? ? ????? ?? ?? ???? ?? ? ????. F ? g ? ?? ?? ??? ??? ?? ?????. ???? ?? ???, f? g? ????? ?? ??? ?? ?????. ?? ???? ? ??? ???Declarative???.
  6. ?? ??? ? ??? ??? ??? ? ??? ??? ? ?? ???.
  7. ??? ?? ??? ??? ? ?? ?? ?? ?? ? ???? ??? ? ????. ???? ??? ?? ??? ?????? ???? ??? ???? ? ????? ??? ???? ?? ? ?? ?? ?? ? ??? ??? ???.
  8. ?? ??? ?????? ????? ?? ????. 1973???? ?? ??? ?? 2013?? ???? ? ????? 1973? ???? ¡¯40? ?? ?????£§? ??? ?????,
  9. ?? 40? ??? ??? ?????? ??? ?????. ??? ?? ?? ?? ???? ??? ?? ??? ??? ??? ??? ????? ??? ??? ? ??? ??? ????.
  10. ??? ?? ???? ??? ???? ???? ?? ????, 70??? 80??? ???? ??? ???? ??? ?? ???.
  11. ?? ???? ????? ???? ??? ? ????? ???? ??? ?? ????? ?? ? ?????? ?? ????, ???? ?? ? ??? ?? ? ??????. ? ??? ???..
  12. ??? ????, ? ???? ????? ?? ? ????, ? ?????? ?? ????? ????, ??? ???? ??? ????? ??? ?????? ??? ?? ??????. ??? ? ??? ?? ? ??? ???? ??? ?? ?? ???? ?? ?? ?????. ?? ??? ??? ??? ???? ?? ???? ?????, ?? ??????? ??? ?? ?? ? ????.
  13. ???? ?????? ??? ??? ??? ????? ??? ? ?? ??? ???????.
  14. ??? ?? ??? ???? ??? ????? 3, 4? ???? C? ??? ???? A, B? ?? ??? C? ?? ???? ????. ??? ?? Reactive Programming ? ?? ???? ?????.
  15. ??????, Reactive ?? C = A + B ?? ??? ?? ?? ??? ?? ??? ??? ??? ?? ????. ????, ???procedural, ???imperative?? ?? ???declarative??, ???? ??? ?? ?? ???? ??? ??? ????. ????? ??? ????? ?? ??? C = A + B ?? ?? A, B? ?? ??? ???? C? ?? ???? ???.
  16. ?, ????? ???? ???? ???? ?? ?? ?? ??? ????? ?? ??? ??? ??? ????, ??? ??? ?? ???? ??? ?? ? ????. ???? ?? ??? ?? ??? ?? ?? ????.
  17. ?? ??? ???? ????? ????. ??? ¡®????¡¯?? ??? ??? ?? ????. ?? ??? ?? ????? CPU? ?? ???? ??? ???, ?? ????? ??? ??? ???? Verilog ?? ???? ?????? ?????? ?????.
  18. ???? ???? ??? ??? ??? ??? ???? ??? ?? ???? ??? ??? ?? ??? ??? ?????.
  19. ?? ?? ?? ??? ??? ???? ?? ?? ??? ?? ???? ???? ?? ???? ?? ???? ?? ?? ?? ?? ?? ????? ???? ???? ?? ???. ??? ??? ????? ???? ???? ???? ??? ?? ???? ?? ?????? ??? ????? ?????.
  20. ??????? ¡°????? ????£¢??? ???? ?? ????? ????? ????? ???, ?? ? ? ?? ????. ?? ?????? ???? ???? ?? ??? ??? ?? ????, ? ? ?? ????? ???? ???? ???? ??? ?? ???????.
  21. ?? ?? ??? ? ????? ?? ???? ???? ?? ????? ?? ??? ????? ???Imperative ???. ???? ???? ??? ?? ???? ??? ??? ????. ????? ??? ?? ???? ?? ??? ????? ??? ????? ??? ??? ?????.
  22. C ??? ????? ?? ?? ??? ??? ?????, ??? ???? ???? ??? ? ???? ? ? ???. ??? C? ??? ???? ????? ?? ??? ???? ??? ???? ?? ??? ???, ????? ?? ???? ???? ¡°????? ?? ¡°? ?????.
  23. ??? ??? C++, Java, C# ? ?? ???? ????? ???? ? ? ?? ????? ???? ?????. ? ???? ??? ???? ??? ??? ?????? ????. ??? ? ???, ????? ????? ??? ?? ???? ? ? ?? ? ????.
  24. ??? ???? ?????? ?? ??? ??? ?? ?? ??????.
  25. ??? ??? ??? ??? ??? ??? ???? ???? ??? ???? ?????? ??? ?? ????? ??????? ? ? ?????. ?? ????? ??? ??? ?? ????? ????
  26. ? ??? ???? ?? ???? ??? ??? ???? ????, ???? ????? ???? ?? ?? ?? ???? ??? ???? ???? ??? ??? ??? ?? ? ??? ?????.
  27. ??? ??? ? ? ????? ???? ????? ?? ??, ??? ???? ????? ???.
  28. ? ? ??? ??? ?? Event-Driven ? ?? ????? ???. Event-Driven ? ???? ??? ??? ?? ??? ?????.
  29. ??? ?? ??? ??? ?? ??? ?????. ??? ??? ???. ? ??? ????? ???? ???, ??? ???? ??? ?? ??? ? ??? ??? ???? ????? ?? ?? ???? ????. ??? ???? ????? ????? ??? ?? ?? ???? ??? ???? ???? ???,
  30. ??? ????? ? ? ?? ?????? ?? ??????? ???? ?? ???. ?? ??? ?? ?? ??? ??? ???? ? ???, ???? ??? ?? ??? ???? ????. ? ??? ???? ??? ???? ??? ???? ?? ????, ?? ??? ???? ? ???? ???? ??? ???. ??? ?? ??? ??? ???? ???? ??? ??? ??? ??????.
  31. ?? ??? ??? ?? ????? ???????? ??? ?? ??? ?????. ??? ? ????? ???? 1000? ??? ??? ? ????.
  32. ??? ?????? ??? ?? ??? ????????? ??? ??? ? ? ?? ???. ???? ????? ??? 4?? ???? ??? ?? ?? ? ???. ??? ? ? ???? ????? ??? ??? ??? ???? ???? ?? ??? ????? ?? ???? ??? ??? ?? ???.
  33. Event Driven ??? ?? ?? ?? ??? ?? ???? ????? ?????. ???? ??? ??? ?? ?????. ?? ??? ?????? ??? ???? ?? ?? ??????? ? ??? IOCP? ????? ?? ??? ??? ??. ¡­ ??? ? NodeJS? VertX? ???? ??? ?? ???.
  34. ??? ??? ?? ??? ??? ?? ?? ???.
  35. NodeJS? ?? ???? ?? ?? ??? ?????. ??? ??? ??,
  36. ?? ???? ??? ??? 3? ??? ??? ??, ?? ??? ?? ?? ?? ?? ?? ??? ???? ???. ? ????? ?????? ????? ??? ????? ??? ? ?? ??? ??????. NodeJS API?? ? ?? ??? ?? ??? ????? ?? ?? ??? ??? ?? ??? ?? ??, ??? ? ?????? ???? ??? ???? ?? ?? ? ?? ????? ???? ?? ???? ???? ???? ???.
  37. ??? ??? ?? ??? ??? ??? ??? ?? ???,
  38. ?? M ?? ??? ??? ? ????.
  39. ? M?? ?? ??? ???? ????? ?????.
  40. ??? ?????? ??? ?? ??? ????? ????? ??? ??. ??? ??? ??? ???? ??? ???? ????? ? ? ??? ???,
  41. ???? ???? ???????.
  42. ??? ? ???? ???? ??? ??? ? ??? ???? ???? ?? ?????.
  43. ????? ? ? ??? ??? ?? Event-Driven ? ?? ????? ???.
  44. ?????? ????? , ?? ?? ???? NodeJS? ??? ???, ?????????? ?????? ?? ?? MVVM ?????? ???? ?????? ??? ???? ????. Q Promise?? ?? ????, Javascript Promise?? ??? ???? ???, Rx? ?????? ??? ?? ????.
  45. ?? ?? ???? ?? ??? ?? Dart? ?? ???? Future? ??? ???? ?????. ?? ??? ??? ?? ? ??.
  46. FRP ???? ???? ??? 3D ????? ??? ? ?? ELM?? ??? ????. ????? ??? ?? ???? ????? ??? ??? ??? ? ? ??? ??????.