RxSwift / RxJava の基本と実践

RxSwift / RxJava の基本と実践

アジェンダ
----
はじめに
Rx を使う動機
基本 30
- Observable はストリーム
- Observable を変換する
- subscribe が大事
- ストリームとデータの流れ
- イベントの種類
- Disposable
発展 10
- マルチスレッド
- ストリーム結合・分割
- Hot / Cold

0886c70b5ecf3b0b0ee6500c5e47884d?s=128

M.Inomata

July 18, 2018
Tweet

Transcript

  1. RxSwift, RxJavaͷ جຊͱ࣮ફ גࣜձࣾ tech vein ழມ ॆԝ

  2. ࣗݾ঺հ גࣜձࣾ tech vein ୅ද ழມ ॆԝ (͍ͷ·ͨ ΈͭͻΖ) ձࣾHP:

    https://www.tech-vein.com/ private twitter: @ino2222
  3. ݸਓతͳࣗݾ঺հ www.ecoop.net ͱ͍͏αΠτΛ2002೥͔ΒӡӦ͍ͯ͠·͢ɻ GNU Make ͱ͍͏ίϚϯυͷӳޠυΩϡϝϯτΛͻͱΓͰίπίπຊҰ࡭෼຋༁ɺ2002೥ʹެ։ͨ͠Γ͠ ·ͨ͠ɻ ࠓ͸ओʹ iOSΞϓϦ։ൃऀΛ͍ͯ͠·͢ɻ WindowsΞϓϦ։ൃ(2000~2003)

    → PHP։ൃ/Πϯϑϥӡ༻(2003~2012) ˍ Java։ൃ(ΨϥέʔΞϓϦˍJavaEE)(2005~2010) → AndroidΞϓϦ։ൃ(2010~2013) → iPhone ΞϓϦ։ൃ(2013~) ʴ α AndroidʹະདྷΛײͨ͡2010೥ʹΞϓϦΛॳΊͯެ։͠ɺ௨ࢉ15ສμ΢ϯϩʔυΛୡ੒ʂ …͢Δ΋ɺެ։̍िؒͰߋ৽༻ͷ伴Λ๨ΕͯϝϯςφϯεෆՄೳʹ…ɻ
  4. ձࣾ(tech vein)ͷ঺հ 2013೥͔Β͋ΔେࡕຊொͷडୗγεςϜ։ൃձࣾͰ͢ɻ Android / iOS εϚʔτϑΥϯΞϓϦ։ൃ΍ɺ WebγεςϜ։ൃ(PHPɾJS)͕ಘҙͰ͢ɻ গਓ਺ͷٕज़తͳ͜ͱɾ໘ന͍͜ͱ͕޷͖ͳϝϯόʔ͕ू·ͬ ͯͰ͖ͨɺখ͞ͳձࣾͰ͢ɻ

    ձ໊ࣾ͸ςοΫϕΠϯͱಡΈ·͢ɻ
  5. ࣗࣾެ։தͷAndroid/iOSΞϓϦ ι΢ϧΞϯϦʔγϡ ࣗ෼ͷΦϦΩϟϥΛ࡞ΔεϚϗ31( IUUQTPVOUFDIWFJODPN IUUQTCJUMZ);BV3 $IJJ2 ஍ҬͰॿ͚߹͑Δಗ໊૬ஊΞϓϦ IUUQTBQQMFDP,[IYD ϙέοτΞϒετϥΫτ ҩྍैࣄऀ޲͚ͷ࠷৽δϟʔφϧߪಡΞϓϦ

  6. ࠓ೔͓࿩͢Δ͜ͱ • RxͷϞνϕʔγϣϯɺخ͍͜͠ͱ • Rx ͷجຊ • εϨουॲཧͱετϦʔϜ݁߹ • (͕࣌ؒ͋Ε͹)

    Hot / Cold ม׵
  7. ࠓ೔͓࿩͠ͳ͍͜ͱ(஌ͬͯΔํ޲͚) • Reactive Streams(backPressure ͳͲ)

  8. ͸͡Ίʹ • αϯϓϧίʔυ͸͢΂ͯ RxSwift Ͱॻ͔Ε͍ͯ ·͢ɻ • RxJava ΍ RxJSͰ΋جຊ͸ಉ͡Ͱ͕͢ɺࡉ͔

    ͍จ๏ɺਖ਼֬ͳϝιου໊͸ҧ͏͜ͱ͕͋Γ ·͢ɻಉ͡༻్ͷϝιου͕͋ΔͷͰɺ࢖͏ ͱ͖͸ஔ͖׵͑ͯԼ͍͞ɻ
  9. RxͷϞνϕʔγϣϯ خ͍͜͠ͱ

  10. RxSwift/RxJavaͱ͸ • ֤ݴޠͰ࣮૷͞Ε͍ͯΔʮRx(Reactive Extension)ʯ
 ͷSwift, Java ޲͚ϥΠϒϥϦ • Reactive Extension

    … ΋ͱ΋ͱ͸
 C#.NET Ͱ࢖ΘΕͩͨ͠ Rx.NET ͕ΦϦδφϧ • JavaScript(RxJS), C++(RxCpp), Ruby(Rx.rb), PHP(RxPHP) ͳͲͳͲଟ਺
  11. Rx=ReactiveXͱ͸Կ͔ʁ ReactiveX = Reactive Extension ൓Ԡతϓϩάϥϛϯά(Reactive Programming)Λ͢ΔͨΊ ͷ֦ுϥΠϒϥϦ(Extensions Library)ͷ͜ͱɻ ReactiveX͸̏ͭͷઃܭࢥ૝Λ૊Έ߹Θͤͯ࡞ΒΕͨϥΠ

    ϒϥϦͰ͢ɻ - GoF σβΠϯύλʔϯͷ Observable ύλʔϯ - GoF σβΠϯύλʔϯͷ Iterator ύλʔϯ - ؔ਺ܕϓϩάϥϛϯά
  12. Α͋͘Δύλʔϯ Rx ͳΜ͔Θ͔ΒΜ Rx ͬͯϦεΫ͕͋Γͦ͏ Rx ͜Θ͍

  13. RxΛͳͥ࢖͏͔ ɾ׳ΕΔͱඇಉظॲཧ͕͔ͳΓָʹͳΔɻ ɾ͓͚֮͑ͯ͹৭ʑͳݴޠɺର৅ʹ࢖͑Δɻ ɾෳࡶͳॲཧͰ΋෭࡞༻Λগͳ͘ॻ͚Δɻ
 ɾجຊΛ཈͑Ε͹ҙ֎ͱ؆୯ɻ

  14. ˣ ͓୊ɿϢʔβ͕ϘλϯΛԡͨ͠Βɺ ɹɹɹඇಉظॲཧ" #Λ଴ͬͯɺ ɹɹɹ݁ՌΛඇಉظॲཧ$ͰՃ޻ͯ͠ɺ ɹɹɹશ෦ͪΌΜͱΤϥʔॲཧΛͯ͠ ɹɹɹ࠷ޙʹ݁ՌΛը໘ʹදࣔͯ͠ཉ͍͠ɻ

  15. ˣ ͓୊ɿϢʔβ͕ϘλϯΛԡͨ͠Βɺ ɹɹɹඇಉظॲཧ" #Λ଴ͬͯɺ ɹɹɹ݁ՌΛඇಉظॲཧ$ͰՃ޻ͯ͠ɺ ɹɹɹશ෦ͪΌΜͱΤϥʔॲཧΛͯ͠ ɹɹɹ࠷ޙʹ݁ՌΛը໘ʹදࣔͯ͠ཉ͍͠ɻ ˞J04 3Y4XJGUͷίʔυྫ

  16. ͕͜͜خ͍͠Rx UIΠϕϯτ΍APIɾDBͷඇಉظॲཧͷ࣮ߦ݁ՌͳͲ͋ΒΏΔΠϕϯ τɾσʔλΛ࣌ܥྻσʔλͷετϦʔϜͱͯ͠ॲཧͰ͖Δɻ ಉظతͳɺ஋ɺ഑ྻ͸΋ͪΖΜɺΤϥʔͰ͑͞΋ετϦʔϜͱͯ͠ ѻ͑Δɻ ετϦʔϜࣗମΛΦϒδΣΫτ(Observable)ͱͯ͠ѻ͏͜ͱͰɺෳ ࡶʹͳΓ΍͍͢ඇಉظॲཧ΋ಉظॲཧ΋ಉ͡ΦϒδΣΫτม׵ʹͳ ΓɺγϯϓϧʹͳΔɻ ετϦʔϜΛ࡞ͬͨΓܨ͍ͩΓɺม׵ͨ͠ΓɺՃ޻͢Δศརͳಓ۩ ͕ἧ͍ͬͯΔɻ

  17. ڵຯͰ͖ͯ·͔ͨ͠ʁ Ͱ͖ͯ·ͨ͠ΑͶʁ

  18. Rxͷجຊ ·ͣ͸Observable͔Β࢝ΊΑ͏

  19. Observable → RxͷओཁΫϥε Rx͕࣋ͭ΄ͱΜͲ͢΂ͯͷΫϥε͸Observable ͱͦͷ೿ੜΫϥε(ʴܑఋΫϥε)Ͱ͢ɻ ·ͣ͸ Observable Λ஌Δ͜ͱ͕RxϚελʔ΁ ͷۙಓʹͳΓ·͢ɻ

  20. Observable ؂ࢹͯ͠σʔλʢΠϕϯτ)Λड͚औΔࣄ͕Ͱ͖ΔΦϒ δΣΫτͰ͢ɻ ॱ൪ʹσʔλɾΠϕϯτ͕ObservableʹྲྀΕΔ͜ͱ͔ ΒɺObservable͸ετϦʔϜ(Stream)ͱ΋ݺͼ·͢ɻ

  21. “Hello” “Rx” “World” Observable<String> completed ࣌ؒͷྲྀΕ Observable ͸ετϦʔϜ

  22. ͜ͷਤΛʮϚʔϒϧμΠΞάϥϜʯͱ͍͍ɺ ̍ͭͷ໼ҹ͕̍ͭͷετϦʔϜ 0CTFSWBCMF Λද͠·͢ɻ ࠨ͔Βॱ൪ʹΠϕϯτ͕ྲྀΕΔΠϝʔδͰ͢ɻ ̍ͭͷʮ˔ʯ͕̍ͭͷཁૉ͕དྷͨ OFYU ΠϕϯτΛද͠ɺ ʮʛʯ͕ऴྃ DPNQMFUFE

    ΠϕϯτΛද͠·͢ɻ “Hello” “Rx” “World” Observable<String> completed ࣌ؒͷྲྀΕ
  23. “Hello” “Rx” “World” Observable<String> completed ࣌ؒͷྲྀΕ ͜ͷਤΛʮϚʔϒϧμΠΞάϥϜʯͱ͍͍ɺ ̍ͭͷ໼ҹ͕̍ͭͷετϦʔϜ 0CTFSWBCMF Λද͠·͢ɻ

    ࠨ͔Βॱ൪ʹΠϕϯτ͕ྲྀΕΔΠϝʔδͰ͢ɻ ̍ͭͷʮ˔ʯ͕̍ͭͷཁૉ͕དྷͨ OFYU ΠϕϯτΛද͠ɺ ʮʛʯ͕ऴྃ DPNQMFUFE ΠϕϯτΛද͠·͢ɻ ͜ͷσʔλͷྲྀΕ͕ ͭͷετϦʔϜ ʹ̍ͭͷ0CTFSWBCMF
  24. Observable͸࡞੒ɾม׵Ͱ͖Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }
  25. Observable͸࡞੒ɾม׵Ͱ͖Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }      <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 ετϦʔϜ࡞੒
  26. Observable͸࡞੒ɾม׵Ͱ͖Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }         <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 ετϦʔϜม׵
  27. Observable͸࡞੒ɾม׵Ͱ͖Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }            <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 2 completed 6 10 ετϦʔϜม׵
  28. subscribe͠ͳ͍ͱετϦʔϜ͸࢝·Βͳ͍ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> ετϦʔϜͷ࡞੒
  29. Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU <*OU>

    ετϦʔϜ 0CTFSWBCMF Λ ฦ͚͢Ͳʜ subscribe͠ͳ͍ͱετϦʔϜ͸࢝·Βͳ͍
  30. Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU <*OU>

    σʔλ͸ྲྀΕͯ͜ͳ͍ʜ ƅшƅ ŴƅŜŖƃʜ subscribe͠ͳ͍ͱετϦʔϜ͸࢝·Βͳ͍
  31. Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU <*OU>

    .subscribe(onNext: { print(“next: \($0)”) }) ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ ˞Ұ෦ )PU0CTFSWBCMF Λআ͘ ƅшƅ Űŕ ಥવͷTVCTDSJCFʂ subscribe͠ͳ͍ͱετϦʔϜ͸࢝·Βͳ͍
  32. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ετϦʔϜͷ։࢝ ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ ˞Ұ෦ )PU0CTFSWBCMF Λআ͘
  33. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ετϦʔϜ͔ΒΠϕϯτ σʔλ ͕ྲྀΕΔ  ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ ˞Ұ෦ )PU0CTFSWBCMF Λআ͘
  34. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ετϦʔϜ͔ΒΠϕϯτ σʔλ Λड͚औΔ ˠlOFYUz  Λग़ྗ͢Δɻ  ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ ˞Ұ෦ )PU0CTFSWBCMF Λআ͘
  35. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ˠlOFYUz  Λग़ྗ͢Δɻ   ετϦʔϜ͔ΒΠϕϯτ σʔλ ͕ྲྀΕΔ ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ ˞Ұ෦ )PU0CTFSWBCMF Λআ͘
  36. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ˠlOFYUz lOFYUz  Λग़ྗ͢Δɻ   ετϦʔϜ͔ΒΠϕϯτ σʔλ Λड͚औΔ ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ ˞Ұ෦ )PU0CTFSWBCMF Λআ͘
  37. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ˠlOFYUz lOFYUz  Λग़ྗ͢Δɻ ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ   தུ
  38. subscribeͰετϦʔϜΛ։࢝͢Δ Observable .from([1,2,3,4,5]) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ 0CTFSWBCMF*OU

    <*OU> .subscribe(onNext: { print(“next: \($0)”) }) lOFYUz ਺஋Λϩάग़ྗ͢Δ ˠlOFYUz lOFYUz ʜ lOFYUz Λग़ྗ͢Δɻ ։࢝ͯ͠ॳΊͯඇಉظͰॱ൪ʹσʔλ͕ྲྀΕ·͢ɻ     
  39. Q: ετϦʔϜม׵͞Ε͍ͯͨΒ Ͳ͏͍͏ಈ͖ʹ ͳΔͰ͠ΐ͏͔ʁ

  40. A. ετϦʔϜม׵͞Ε͍ͯͯ΋ɺ subscribeޙͷॲཧͷྲྀΕ͸ ಉ͡Πϝʔδ

  41. subscribe͢Δ·Ͱ΍ͬͺΓσʔλ͸ྲྀΕͳ͍ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 } <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> ੩͔ͩʜ ɾТɾA
  42. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 } .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> ετϦʔϜͷ։࢝
  43. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 2 completed 6 10
  44. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }   .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 2 completed 6 10 ̍͸ح਺ͳͷͰ0,ʂ
  45. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }    .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 2 completed 6 10 ̍ˎ̎ʹ̎
  46. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }    ˠlOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ 2 completed 6 10
  47. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }     ˠlOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ 2 completed 6 10
  48. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }     ˠlOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ ̎͸ۮ਺ͳͷͰεΩοϓʂ 2 completed 6 10
  49. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }      ˠlOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ 2 completed 6 10
  50. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }       ˠlOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ 2 completed 6 10 ̏͸ح਺ͳͷͰ0,ʂ
  51. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }        ˠlOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ 2 completed 6 10 ̏ˎ̎ʹ̒
  52. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }        ˠlOFYUz lOFYUz  .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 Λग़ྗ͢Δɻ 2 completed 6 10
  53. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }            ˠlOFYUz lOFYUz lOFYUz Λग़ྗ͢Δɻ .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 2 completed 6 10 தུ
  54. Observable͸ඇಉظʹॱʹσʔλ͕ྲྀΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 }            ˠlOFYUz lOFYUz lOFYUz Λग़ྗ͢Δɻ .subscribe(onNext: { print(“next: \($0)”) }) <    > ഑ྻ͔Β0CTFSWBCMFετϦʔϜΛ࡞Δ ح਺͚ͩ࢒͢ϑΟϧλΛ͔͚Δ ̎ഒͷ஋ʹม׵͢Δ lOFYUz ਺஋Λϩάग़ྗ͢Δ 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> 1 completed 2 3 4 5 1 completed 3 5 2 completed 6 10
  55. Observable ͸ subscribeͨ͠Βಈ͖ग़͢ Observable .from([1,2,3,4,5]) .filter { $0 % 2

    == 1 } .map { $0 * 2 } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF TVCTDSJCF
  56. ಈ͖ग़ͨ͠Β্ྲྀ͔ΒԼྲྀʹΠϕϯτ(σʔλ)͕ྲྀ ΕΔ Observable .from([1,2,3,4,5]) .filter { $0 % 2 ==

    1 } .map { $0 * 2 } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF TVCTDSJCF PO/FYU PO/FYU PO/FYU
  57. ετϦʔϜʹྲྀΕΔ Πϕϯτͷछྨ

  58. ετϦʔϜͷΠϕϯτ • next
 σʔλ͕ਖ਼͘͠ྲྀΕ͖ͯͨͱ͍͏Πϕϯτɻ೚ҙͷܕͷσʔλΛҾ਺ʹ࣋ ͭɻ • error
 ετϦʔϜத͕Τϥʔ(ྫ֎)Ͱҟৗఀࢭͨ࣌͠ʹྲྀΕΔΠϕϯτɻൃੜͨ͠ ΤϥʔΛҾ਺ʹ࣋ͭɻ •

    completed
 ετϦʔϜ͕ਖ਼͘͠׬ྃͨ࣌͠ʹൃੜ͢ΔΠϕϯτɻετϦʔϜͷ࠷ޙʹ Ұ౓͚ͩൃੜ͢Δɻ
 ʢೖྗΛ଴ͪଓ͚͍ͨͱ͖͸completedΛྲྀ͞ͳ͍ʣ
  59. ετϦʔϜͷΠϕϯτ next completed next next next next next completed next

    next ετϦʔϜ͸ next ͰσʔλΛྲྀ͠ɺDPNQMFUFEͰऴྃ͢Δ DPNQMFUFE͕དྷͨΒɺͦͷઌ͸OFYUFSSPS͸ྲྀΕͳ͍ ྲྀͤͳ͍ next next next FSSPS ྫ֎ ͕དྷͨΒɺͦͷઌ͸OFYUDPNQMFUFEFSSPS͸ྲྀΕͳ͍ ྲྀͤͳ͍ error next next next next next DPNQMFUFE͠ͳ͍ετϦʔϜͰӬٱʹOFYUΛ଴ͪଓ͚Δ͜ͱ΋Ͱ͖Δ next
  60. Observableͷ·ͱΊ - Observable͸ετϦʔϜ - ԿͰ΋Observableʹ͢Δࣄ͕Ͱ͖Δ - Observable͸ม׵ͯ͠ผͷObservableΛੜ੒͢Δ͜ͱ͕Ͱ ͖Δ - subscribeͰετϦʔϜ͔ΒσʔλΛड͚औΔ

    - جຊతʹ subscribe ͢Δ·Ͱ͸ετϦʔϜ͕ྲྀΕͳ͍ - subscribeͨ͠Β࿈࠯Ͱඇಉظʹσʔλ͕ྲྀΕग़͢
  61. Πϕϯτͷ·ͱΊ ObservableͰड͚औΔΠϕϯτ͸ جຊ next, error, completed ͚ͩɻ (ଞʹ͸disposed, subscribedΠϕϯτΛड͚औΕͨΓ͠·͕͢ɺ͋·Γ࢖Θͳ͍Ͱ͢)

  62. ετϦʔϜ࣮ߦͷऴྃॲཧ (Disposable) ετϦʔϜΛ։࢝(subscribe) ͢Δͱ໭Γ஋ͱͯ͠ Disposable Λฦ͠·͢ɻ Disposableʹରͯ͠dispose()ΛݺͿ͜ͱͰɺඇಉظॲཧͷΩϟ ϯηϧͳͲɺ؂ࢹ͢Δଆͱͯ͠ॲཧΛࢭΊΔࣄ͕Ͱ͖·͢ɻ ྫɿը໘Λดͨ͡Β௨৴Ωϟϯηϧͨ͠Γɺೖྗ଴ͪΛࢭΊͨ Γ͢Δɻ

  63. Ϣʔβ͔ΒͷϘλϯೖྗΠϕϯτΛ ଴ͪଓ͚Δ0CTFSWBCMF 0CTFSWBCMF*OU Disposableͷ࢖͍ํ %JTQPTBCMF TVCTDSJCF͸ %JTQPTBCMFΛฦ͢ let observable: Observable<Void>

    = executeButton.rx.tap .asObservable() EJTQPTFͰ TVCTDSJCFΛఀࢭ let disposable = observable.subscribe(onNext: { print(“Ϙλϯ͕ԡ͞Ε·ͨ͠”) }) ্ͷ0CTFSWBCMFΛ TVCTDSJCFͰ଴ͪଓ͚ΔॲཧΛ։࢝
  64. ͍ͭDispose͢Δͷ͔ʁ ॲཧ͕׬ྃͨ࣌͠(completed / error͕ྲྀΕͨ ࣌)͸ࣗಈͰ dispose ͞Ε·͢ɻ ௕͕͔͔࣌ؒ͘Δॲཧ΍ɺͣͬͱ଴ͪଓ͚ΔϢʔ βΫϦοΫΠϕϯτͷ؂ࢹͳͲ͸ɺը໘Λด ͨ͡ͱ͖ͳͲɺෆཁʹͳͬͨλΠϛϯάͰ

    disposeͰΩϟϯηϧɾఀࢭͤ͞·͢ɻ
  65. CompositeDisposable ؅ཧର৅ͷ Disposable Λ·ͱΊͯdisposeͰ ͖ΔΫϥεɻը໘಺ͷdisposableΛҰׅఀࢭ ͤ͞Δ࣌ͳͲʹͱͯ΋ศརͰ͢ɻ

  66. ิ଍ɿRxSwiftͷDisposeBag ը໘ͳͲɺ؂ࢹݩΠϯελϯε͕ࢮΜͩΒࣗ ಈͰͥΜͿdisposeͤ͞Δͱ͖ʹ࢖͑Δศར Ϋϥεɻ ˠ3Yඪ४Ͱ͸ͳ͍Ͱ͕͢ɺ3Y4XJGUͰ͸ $PNQPTJUF%JTQPTBCMFͷ୅ΘΓʹ%JTQPTF#BHΛ ࢖͍·͢ɻ

  67. ൃలฤ

  68. ϚϧνεϨουॲཧ Observableʹ͸ - (্ྲྀͷ)ΠϕϯτൃߦΛͲͷεϨουͰॲཧ͢Δ͔ - (ԼྲྀͰ)ड͚औΔ࣌ʹͲͷεϨουͰॲཧ͢Δ͔ ͷ̎छྨͷεϨουίϯτϩʔϧϝιου͕͋Γ· ͢ɻ

  69. ϚϧνεϨουॲཧ - (্ྲྀͷ)ΠϕϯτൃߦΛͲͷεϨουͰॲཧ͢Δ͔ → subscribeOn(<εϨουࢦఆ>) ྫɿAPIͷ௨৴࣮ߦεϨουΛόοΫͰಈ͔͍ͨ͠ - (ԼྲྀͰ)ड͚औΔ࣌ʹͲͷεϨουͰॲཧ͢Δ͔ → observeOn(<εϨουࢦఆ>)

    ྫɿ݁Ռදࣔ͸UIεϨουͰॲཧ͍ͨ͠
  70. ্ྲྀͷεϨουΛม͑Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF PO/FYU PO/FYU TVCTDSJCF࣮ߦεϨου ϝΠϯεϨου όοΫάϥ΢ϯυεϨου
  71. ্ྲྀͷεϨουΛม͑Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF TVCTDSJCF PO/FYU PO/FYU PO/FYU .subscribeOn(ConcurrentD ispatchQueueScheduler(qos : .background)) TVCTDSJCF࣮ߦεϨου ϝΠϯεϨου όοΫάϥ΢ϯυεϨου
  72. ԼྲྀͷεϨουΛม͑Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF PO/FYU PO/FYU TVCTDSJCF࣮ߦεϨου ϝΠϯεϨου όοΫάϥ΢ϯυεϨου
  73. ԼྲྀͷεϨουΛม͑Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF TVCTDSJCF PO/FYU PO/FYU PO/FYU .observeOn(MainSchedula r.instance) TVCTDSJCF࣮ߦεϨου ϝΠϯεϨου όοΫάϥ΢ϯυεϨου
  74. ૊Έ߹Θͤ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> TVCTDSJCF TVCTDSJCF TVCTDSJCF PO/FYU PO/FYU PO/FYU .subscribeOn(ConcurrentD ispatchQueueScheduler(qos : .background)) .observeOn(MainSchedula r.instance) PO/FYU TVCTDSJCF TVCTDSJCF࣮ߦεϨου ϝΠϯεϨου όοΫάϥ΢ϯυεϨου 0CTFSWBCMF*OU
  75. ϚϧνεϨουॲཧͷ·ͱΊ APIͳͲཪͰ࣮ߦ͍ͨ͠ॏ͍ॲཧ͸ subscribeOn() ͰόοΫάϥ΢ϯυεϨουΛࢦఆ͢Δɻ ड͚औΓΛϝΠϯεϨουͰߦ͍͍ͨ࣌͸ observeOn()ͰϝΠϯεϨουΛࢦఆ͢Δɻ εϚϗΞϓϦ։ൃͰ͸͜Ε͚͓͚֮ͩ͑ͯ͹OKɻ

  76. ετϦʔϜ݁߹

  77. Observable͸৭ʑͳํ๏(Φ ϖϨʔλ)Ͱ࿈݁ɾ݁߹͢Δ͜ ͱ͕Ͱ͖·͢ ɾObservableม׵(طग़ / ݁ՌΛड͚औͬͯॱ൪ʹॲཧ ͢Δ) ɾฒྻͭͳ͗(ObservableΛಉ࣮࣌ߦ͢Δ) ɾ௚ྻͭͳ͗(Observableͷ݁ՌΛड͚औͬͯผͷ ObservableΛॲཧ͢Δ)

  78. Observable .zip( ) ฒྻͭͳ͗(zip ΦϖϨʔλ) Observable .from([1,2,3,4,5]) 0CTFSWBCMF*OU 0CTFSWBCMF*OU Observable

    .from([10,9,8,7,6]) 0CTFSWBCMF*OU 0CTFSWBCMF *OU *OU                     .map { a, b in a * b }
  79. Observable .zip( ) ฒྻͭͳ͗(zip ΦϖϨʔλ) Observable .from([1,2,3,4,5]) 0CTFSWBCMF*OU 0CTFSWBCMF*OU Observable

    .from([10,9,8,7,6]) 0CTFSWBCMF*OU 0CTFSWBCMF *OU *OU                     .map { a, b in a * b } [JQΦϖϨʔλͰ " #݁߹ ී௨ͷ0CTFSWBCMF" ී௨ͷ0CTFSWBCMF# ݁߹݁Ռ͸ " #  " #  ͱ͍͏ετϦʔϜ
  80. .flatMap{ a in } self.fetchAPI(a) ௚ྻͭͳ͗(flatMap ΦϖϨʔλ) Observable .from([1,2,3,4,5]) B*OU

    0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU .map { $0 * 2 }
  81. .flatMap{ a in } self.fetchAPI(a) ௚ྻͭͳ͗(flatMap ΦϖϨʔλ) Observable .from([1,2,3,4,5]) B*OU

    0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU qBU.BQΦϖϨʔ λͰ "͔Β#ʹͭͳ͙ ී௨ͷ0CTFSWBCMF" "͔ΒྲྀΕͨ஋Λ࢖͍ɺ "1*௨৴ͯ݁͠ՌΛྲྀ͢ 0CTFSWBCMF# .map { $0 * 2 }
  82. ෼ׂ΋Ͱ͖Δ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .map { $0 * 2 } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU 0CTFSWBCMF*OU <*OU> %JTQPTBCMF
  83. ෼ׂ΋Ͱ͖·͢ Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1

    } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU <*OU> .map { $0 * 2 } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU 0CTFSWBCMF*OU .subscribe(onNext: { print(“next: \($0)”) }) %JTQPTBCMF %JTQPTBCMF %JTQPTBCMF
  84. ෼ׂͨ͠৔߹͸subscribe࣌ʹετϦʔϜม׵աఔ ͕ෳ੡͞Ε·͢ɻ Observable .from([1,2,3,4,5]) .filter { $0 % 2 ==

    1 } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU <*OU> .map { $0 * 2 } 0CTFSWBCMF*OU 0CTFSWBCMF*OU .subscribe(onNext: { print(“next: \($0)”) }) Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1 } 0CTFSWBCMF*OU <*OU> 0CTFSWBCMF*OU .map { $0 * 2 } .subscribe(onNext: { print(“next: \($0)”) }) 0CTFSWBCMF*OU Observable .from([1,2,3,4,5]) .filter { $0 % 2 == 1 } 0CTFSWBCMF*OU <*OU> 0CTFSWBCMF*OU %JTQPTBCMF %JTQPTBCMF %JTQPTBCMF ͢΂ͯผͷաఔͰ ετϦʔϜΛ TVCTDSJCF͍ͯ͠Δ
  85. (தڃ)ෳ੡ͤ͞ͳ͍ͨΊͷtips Hot ͱ Cold Observable ͸ Cold / Hot ʹ෼͔Ε͍ͯͯɺ

    جຊ͸໌ࣔతʹHotม׵͠ͳ͍ݶΓ Cold Observable ͱࢥ͓͍ͬͯ ͨ΄͏͕͍͍Ͱ͢ɻ(ݫີʹ͸ҧ͍·͕͢؆୯ͷͨΊ) Cold͸subscribe͞ΕΔ·Ͱಈ͔ͣɺsubscribeͷ౎౓ෳ੡͞ΕΔ(1͔ ΒετϦʔϜ͕࢝·Δ)ͱ͍͏ಛ௃͕͋Γ·͢ɻ Hot͸subscribe͞Εͳͯ͘΋ಈ͖ɺ̎ͭҎ্ͷsubscribe͕͋ͬͯ΋ ಉ͡ετϦʔϜΛڞ༗͠·͢ɻ
  86. Hot / Cold ม׵: Cold → Hot share(), shareReplay(), publish()

    ͳͲͷ Hotม׵ΦϖϨʔλʹΑΓHot ʹม׵Ͱ͖· ͢ɻ
  87. Hot / Cold ม׵: Hot → Cold share(), shareReplay(), publish()

    Ҏ֎ͷ΄΅ ͢΂ͯͷΦϖϨʔλ͸ Cold ͳ Observable Λฦ͠·͢ɻ ྫɿ filter, map, from, flatMap, zipͳͲ
  88. Hotม׵ͱݺ͹ΕΔΦϖϨʔλʹΑΓɺ ෳ੡͞Εͳ͘ͳΓ·͢ɻ Observable .from([1,2,3,4,5]) .filter { $0 % 2 ==

    1 } 0CTFSWBCMF*OU <*OU> 0CTFSWBCMF*OU %JTQPTBCMF .share() %JTQPTBCMF IPUม׵ͷྫ TIBSF ΦϖϨʔλ 0CTFSWBCMF*OU .subscribe(onNext: { print(“next: \($0)”) }) .subscribe(onNext: { print(“next: \($0)”) }) ಉ͡ετϦʔϜΛ࢖͍ճ͢ ʹ৽ͨʹੜ੒͠ͳ͍͍ͯ͘෼ίετ͕௿͍
  89. Hotม׵ͷϝϦοτ ɾԿ౓΍ͬͯ΋ಉ݁͡ՌʹͳΔ͕ɺॲཧʹ࣌ ͕͔͔ؒΔίετ୹ॖͰ͖Δ Hotม׵ͷσϝϦοτ ɾཧղͤͣʹ࢖͏ͱλΠϛϯάʹΑͬͯ͸ظ଴௨Γ Πϕϯτ͕དྷͳ͘ͳΓɺϋϚΔɻ (ઌʹଞͷsubscribe()͕͍Δ͔Ͳ͏͔Ͱڍಈ͕ม ΘͬͨΓ͢Δ)

  90. ColdͷϝϦοτ ɾΘ͔Γ΍͍͢ ColdͷσϝϦοτ ɾ৔߹ʹΑͬͯ͸ॲཧ͕ॏ͘ͳΔ →ύϑΥʔϚϯεͷ໰୊͕ग़͔ͯΒ ɹHot/Coldʹ͍ͭͯௐ΂Ε͹OKͩͱࢥ͍· ͢ɻ

  91. Hot / Cold ·ͱΊ ׳ΕͨΒ࢖ͬͯΈΑ͏ɻ ׳Εͳ͍͏ͪ͸৮Βͳ͍΄͏͕٢ɻ

  92. ·ͱΊ • Πϕϯτɾσʔλ͸ԿͰ΋RxԽͰ͖ΔɻΠϕϯ τɾσʔλͷ΍ΓऔΓΛετϦʔϜͱͯ͠ߟ͑Α ͏ • ॲཧͷεςοϓ(ϑΟϧλɺܭࢉɺσʔλಡΈॻ͖) ΛετϦʔϜม׵ͱଊ͑Α͏ɻ • RxΛۃΊͨΒඇಉظॲཧ΋γϯϓϧʹ෭࡞༻ͳ

    ͘ɺεϚʔτʹॻ͚ΔΑ͏ʹͳΓ·͢ɻ
  93. Rx ͸؆୯ʹࢼͤ·͢ • Java, Kotlin ։ൃ؀ڥ͕͋ΔͳΒ… • Grade Ͱ RxJava2,

    RxAndroid, RxKotlinΛೖΕͯΈΔɻ • Swift ։ൃ؀ڥ͕͋ΔͳΒ… • CocoaPods Ͱ RxSwiftΛೖΕͯΈΔɻ • Ͳͬͪ΋ͳ͍৔߹ • RxJS Playground ͰͳΜͱϒϥ΢βͰࢼͤΔʂ • https://rxjs-playground.github.io/ (RxJS Playground Ͱݕࡧ)
  94. ͍͞͝ʹ • tech vein Ͱ͸͜ΜͳΞϓϦΤϯδχΞɺ
 ϑϦʔϥϯεɾύʔτφʔ༷Λืू͍ͯ͠·͢ɻ • RxSwift, RxJava Λ࢖͍͍ͨ

    • MVVMɺ CleanArchitectureɺ DI Λ׆༻ͨ͠ઃܭʹڵຯ͕͋Δ ڵຯ͕͋Δํɺͪΐͬͱ࿩Λฉ͍ͯΈ͍ͨํ
 ͨͩ3Yͷ࿩Λ΋ͬͱฉ͖͍ͨํ΋
 ͥͻ͓੠͕͚Լ͍͞ʂ
  95. ࢀߟ • RxSwift / RxJava Observable νʔτγʔτ
 https://docs.google.com/spreadsheets/u/1/d/ 12C3MLr2RfrYPezHJTmjruDt3i8TRZGCJDnVz86vo39g/edit#gid=0 •

    SubjectͱRelayͷҧ͍ͳͲObservableͷ೿ੜΫϥεͷ࢓༷Λ·ͱΊͨਤͰ͢ɻ • RxSwift + RxCocoa Λ࢖ͬͨ؆୯ͳΞϓϦ • GitHub:
 https://github.com/ecoopnet/rxswift-beginner • ࢀߟهࣄ • Կͱͳ͘RxJavaΛ࢖ͬͯΔ͚Ͳਖ਼௚Α͘෼͔ͬͯͳ͍ਓ͕ಡΉͱྑͦ͞͏ͳهࣄɾجૅฤ
 https://qiita.com/k-mats/items/4d374460a3f6284dd09f
  96. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ

  97. ͓·͚ɿRxͷجຊ Rxͷߟ͑ํͷجૅ

  98. ReactiveXͱ͸Կ͔ʁ ReactiveX = Reactive Extension ൓Ԡతϓϩάϥϛϯά(Reactive Programming)Λ͢ΔͨΊ ͷ֦ுϥΠϒϥϦ(Extensions Library)ͷ͜ͱɻ ReactiveX͸̏ͭͷઃܭࢥ૝Λ૊Έ߹Θͤͯ࡞ΒΕͨϥΠ

    ϒϥϦͰ͢ɻ - GoF σβΠϯύλʔϯͷ Observable ύλʔϯ - GoF σβΠϯύλʔϯͷ Iterator ύλʔϯ - ؔ਺ܕϓϩάϥϛϯά ʁ ࠶ܝ
  99. Observerύλʔϯ σʔλΛ؂ࢹ͢Δਓͱ఻͑Δ࢓૊ΈΛ ந৅Խͨ͠σβΠϯύλʔϯ ͕͜͜େࣄʂ

  100. 0CTFSWFS͕4VCKFDUʹBEE0CTFSWFSͰࣗ෼Λొ࿥

  101. ݁Ռ௨஌͢Δͱ͖͸4VCKFDU͕OPUJGZ͢Δ

  102. $PODSFUFΫϥεಉ࢜͸ɺ ͓ޓ͍Λ஌Βͳ͍··ɺଟରଟͷؔ܎Ͱɺ ΠϕϯτΛ΍ΓऔΓͰ͖Δ

  103. Iterator ύλʔϯ https://ja.wikipedia.org/wiki/Iterator_ύλʔϯ ೚ҙͷσʔλΛॱ൪ʹॲཧ͢ΔσβΠϯύλʔϯ ͕͜͜େࣄʂ

  104. ࣍ͷσʔλΛॱ൪ʹ next() Ͱऔͬͯ͘Δ͚ͩͳͷͰɺ Iteratorͷ࣮ମ͕Կ݅͋ͬͯ΋ɺͲ͏͍͏σʔλߏ଄Ͱ͋ͬͯ΋ɺ ͨͱ͑σʔλ͕શ෦ἧ͍ͬͯͳͯ͘΋ɺಉ͡ํ๏Ͱॱ൪ʹऔಘͰ͖Δ ʁ *UFSBUPS 4USJOH ·ͩ͋Δʁ IBT/FYU

    ͋ΔΑ USVF ͍ͩ͘͞ OFYU Ͳ͏ͧ lIPHFz
  105. ؔ਺ܕϓϩάϥϛϯά ˠ ͦΕͧΕͷؔ਺͸ */065ʹ͔͠ Өڹ͠ͳ͍ ˠ෭࡞༻͕ͳ͍ Α͏ʹॻ͚Δ

  106. Rx ʹ Observerύλʔϯ + Iterator ύλʔϯ + ؔ਺ܕϓϩάϥϛϯά ग़యIUUQSFBDUJWFYJP