Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

dart:async로 맛보는 Functional Reactive Programming

1,556 views

Published on

Published in: Software
  • Be the first to comment

dart:async로 맛보는 Functional Reactive Programming

  1. 1. 2
  2. 2. 3
  3. 3. • • f : X → Y int main() { return 42; } a b c 1 2 3 X Y f 4
  4. 4. a b c 1 2 3 X Y f : X → Y ㄱ ㄴ ㄷ Z g : Y → Z f g 5
  5. 5. a b c X ㄱ ㄴ ㄷ Z g ∘ f : X → Z g ∘ f 6
  6. 6. … int y = f(x); int z = g(y); … 7
  7. 7. f g 8
  8. 8. g ∘ f 9
  9. 9. 10
  10. 10. ANYTHING 11
  11. 11. 12
  12. 12. 13
  13. 13. 14
  14. 14. 15
  15. 15. 17
  16. 16. A = 3 B = 4 C = A + B A = 4 B = 5 print C 18
  17. 17. 19
  18. 18. C = A + B + A C B 20
  19. 19. 21
  20. 20. 22
  21. 21. © Behringer 23
  22. 22. © Manu Cornet 24
  23. 23. 25
  24. 24. 1 • • • 26
  25. 25. 10-3• • • 27
  26. 26. 10-6• • • 컨텍스트 스위치 28
  27. 27. 10-9• • • 29
  28. 28. • • • • • • • • 30 너무 느림!!
  29. 29. OUTPUT foo(INPUT a); 31
  30. 30. • • • • • • • • 32 너무 느림!!
  31. 31. © Peter Thomas 33
  32. 32. 34
  33. 33. 35
  34. 34. 36
  35. 35. • • • • • • • 37
  36. 36. function foo(a, callback); 38
  37. 37. foo(a, function(err, result) { if (err) { // handle error } else { // use result } ); 39
  38. 38. // 흔한 콜백 지옥 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); }); }); }); } 40
  39. 39. 41 OUTPUT foo(INPUT a);
  40. 40. Future<OUTPUT> foo(INPUT a); 42
  41. 41. Stream<OUTPUT> foo(INPUT a); 43
  42. 42. INPUT => Future<OUTPUT> INPUT => OUTPUT 44 INPUT => Stream<OUTPUT>
  43. 43. 45
  44. 44. 46
  45. 45. • • • • • • 47
  46. 46. 48 https://www.dartlang.org/performance/
  47. 47. 49
  48. 48. 하나 다수 동기 T Iterable<T> 비동기 Future<T> Stream<T> 50
  49. 49. File file = new File("foo.txt"); print(file.readAsStringSync());
  50. 50. File file = new File("foo.txt"); Future future = file.readAsString(); future.then((content) => process(content)) .catchError((e) => handleError(e));
  51. 51. File file = new File("foo.txt"); Future future = file.readAsString(); future.then(expensiveA) .then(expensiveB) .then(expensiveC) .catchError((e) => handleError(e));
  52. 52. 하나 다수 동기 T Iterable<T> 비동기 Future<T> Stream<T> 54
  53. 53. 55
  54. 54. Iterable (pull) Stream (push) getDataFromLocalMemory() .skip(10) .take(5) .map((s) => s + "foo") .forEach(print) getDataFromNetwork() .skip(10) .take(5) .map((s) => s + "foo") .forEach(print) 56
  55. 55. +3 +4 Stream<int> add(Stream<int> input) { return input.map((x) => x+3) .map((y) => y+4); } 57
  56. 56. query1 query2 Future<int> query1(int input); Future<int> query2(int input); Stream<int> query(Stream<int> input) { return input.asyncMap(query1) .asyncMap(query2); } 58
  57. 57. stdin Stream<List<Int> HttpServer Stream<HttpRequest> HttpRequest Stream<List<int>> HttpClientResponse Stream<List<int>> RawServerSocket Stream<RawSocket> RawSocket Stream<RawSocketEvent> WebSocket Stream<List<int>> 또는 Stream<String> 59
  58. 58. 60
  59. 59. 61
  60. 60. http://www.reactive-streams.org/ 62
  61. 61. 63
  62. 62. 64
  63. 63. 65
  64. 64. 67

×