Slide 1

Slide 1 text

NPCJMFTUNO 👋͞Α͏ͳΒ3Y4XJGU 🤗͜Μʹͪ͸ˎ ˎˎˎˎ

Slide 2

Slide 2 text

5PNPLJ,PCBZBTIJ !UFNPLJ w ϞόΠϧΞϓϦΤϯδχΞ J04 "OESPJE 'MVUUFS w J1IPOF(೔ຊ্཮ ೥ ͱಉ࣌ʹ J1IPOFΞϓϦ։ൃΛ࢝ΊΔ w ελϝϯ0# w ηΧϯυϋ΢εͰͷੜ׆Λຬ٤தʜʁ🐒🐒🐒 bento.me/temoki

Slide 3

Slide 3 text

3Y4XJGU "TZODISPOPVT1SPHSBNNJOHXJUI0CTFSWBCMF4USFBNT w .JDSPTPGUىݯͷ3FBDUJWF9ͷ4XJGU࣮૷ w ࣌ؒͷܦաͱͱ΋ʹมԽ͢ΔσʔλΛ 4FRVFODFͷΑ͏ʹѻ͏͜ͱ͕Ͱ͖Δ w ඇಉظॲཧίʔϧόοΫ஍ࠈͷ ιϦϡʔγϣϯͷ̍ͭ w .77.ʴσʔλόΠϯσΟϯάΛ "QQMFϓϥοτϑΥʔϜͰ࣮ݱՄೳ qiita.com/temoki/items/b 8 5 9 b 5 5 a 0 6 bd 8 6 fdfe 2 5 w ϨΨγʔʹͳͬͯ͠·ͬͨײ͕͋Δʜ

Slide 4

Slide 4 text

👋͞Α͏ͳΒ3Y4XJGU ͷલʹ

Slide 5

Slide 5 text

+40/"1* 👋͞Α͏ͳΒ3Y4XGJUͷલʹ ͱ͋ΔϓϩδΣΫτͷґଘؔ܎ʜʢ3Y4XJGUґଘ͞Ε͗͢໰୊ʣ "QQ "MBNP SF 3Y4XJGU .PZB +BQY 3FBDUJWF 4XJGU +40/"1*1BSTFS /FUXPSL"CTUSBDUJPO )551/FUXPSLJOH "TZODISPOPVT1SPHSBNNJOH XJUI0CTFSWBCMF4USFBNT 👋

Slide 6

Slide 6 text

+40/"1* 👋͞Α͏ͳΒ3Y4XGJUͷલʹ ͱ͋ΔϓϩδΣΫτͷґଘؔ܎ʜʢ3Y4XJGUґଘ͞Ε͗͢໰୊ʣ "QQ "MBNP SF 3Y4XJGU .PZB 3FBDUJWF 4XJGU +40/"1*1BSTFS /FUXPSL"CTUSBDUJPO )551/FUXPSLJOH "TZODISPOPVT1SPHSBNNJOH XJUI0CTFSWBCMF4USFBNT 👋

Slide 7

Slide 7 text

"1*$MJFOU "QQ +40/"1* 👋͞Α͏ͳΒ3Y4XGJUͷલʹ ͱ͋ΔϓϩδΣΫτͷґଘؔ܎ʜʢ3Y4XJGUґଘ͞Ε͗͢໰୊ʣ "MBNP SF 3Y4XJGU +40/"1*1BSTFS /FUXPSL"CTUSBDUJPO )551/FUXPSLJOH "TZODISPOPVT1SPHSBNNJOH XJUI0CTFSWBCMF4USFBNT 👋

Slide 8

Slide 8 text

👋͞Α͏ͳΒ3Y4XJGU 4JOHMF

Slide 9

Slide 9 text

3Y4XGJU4JOHMFˠ import RxSwift func fetchIssues() -> Single<[Issue]> { ... } fetchIssues() .map { issues in issues.filter { $0.authorId == myId } } .subscribe( onSuccess: { myIssues in print(myIssues) }, onFailure: { error in print(error) } ) import Combine func fetchIssues() -> Future<[Issue], Error> { ... } fetchIssues() .map { issues in issues.filter { $0.authorId == myId } } .sink( receiveCompletion: { completion in switch completion { case .finished: print("finished") case .failure(let error): print(error) } }, receiveValue: { myIssues in print(myIssues) } ) $PNCJOF'VUVSF

Slide 10

Slide 10 text

3Y4XGJU4JOHMFˠ import RxSwift func fetchIssues() -> Single<[Issue]> { ... } fetchIssues() .map { issues in issues.filter { $0.authorId == myId } } .subscribe( onSuccess: { myIssues in print(myIssues) }, onFailure: { error in print(error) } ) func fetchIssues() async throws -> [Issue] { ... } do { let issues = try await fetchIssues() let myIssues = issues.filter { $0.authorId == myId } print(myIssues) } catch { print(error) } BTZODBXBJU

Slide 11

Slide 11 text

👋͞Α͏ͳΒ3Y4XJGU 0CTFSWBCMF

Slide 12

Slide 12 text

3Y4XGJU0CTFSWBCMFˠ import RxSwift func issuesObservable() -> Observable<[Issue]> { ... } issuesObservable() .map { issues in issues.filter { $0.authorId == myId } } .subscribe( onNext: { myIssues in print(myIssues) }, onError: { error in print(error) }, onCompleted: { print("completed") } ) import Combine func issuesPublisher() -> AnyPublisher<[Issue], Error> { ... } issuesPublisher() .map { issues in issues.filter { $0.authorId == myId } } .sink( receiveCompletion: { completion in switch completion { case .finished: print("finished") case .failure(let error): print(error) } }, receiveValue: { myIssues in print(myIssues) } ) $PNCJOF1VCMJTIFS

Slide 13

Slide 13 text

3Y4XGJU0CTFSWBCMFˠ import RxSwift func issuesObservable() -> Observable<[Issue]> { ... } issuesObservable() .map { issues in issues.filter { $0.authorId == myId } } .subscribe( onNext: { myIssues in print(myIssues) }, onError: { error in print(error) }, onCompleted: { print("completed") } ) func issuesStream() -> AsyncThrowingStream<[Issue], Error> { ... } do { for try await myIssues in issuesStream() .map({ issues in issues.filter { $0.authorId == myId } }) { print(myIssues) } } catch { print(error) } "TZOD4FRVFODF

Slide 14

Slide 14 text

🤗͜Μʹͪ͸ "TZOD4FRVFODF

Slide 15

Slide 15 text

🤗͜Μʹͪ͸"TZOD4FRVFODF ࠓ೔͸͜ΕΛਪ͠ʹ͖ͨʂ w 3Y4XJGU΍$PNCJOFͷΑ͏ͳඇಉظγʔέϯεΛѻ͏4XJGUͷݴޠػೳ w 4FRVFODFͷඇಉظόʔδϣϯɺඇಉظͰྲྀΕΔ஋ΛGPSʜJOͰѻ͑Δ ·ͨɺ4RFVFODFͱಉ༷NBQ GJMUFSͳͲͷΦϖϨʔλ͕ར༻Մೳ w ΦʔϓϯιʔεΫϩεϓϥοτϑΥʔϜ NBD04 -JOVY 8JOEPXT w "QQMFͷϑϨʔϜϫʔΫͰͷରԠ͕ਐΜͰ͍Δ ྫ /PUJGJDBUJPO$FOUFSOPUJGJDBUJPOT OBNFEPCKFDU 63-MJOFT

Slide 16

Slide 16 text

🤗͜Μʹͪ͸"TZOD4FRVFODF ඇಉظγʔέϯεͰγϯϓϧͳߏ଄Խϓϩάϥϛϯά͕Ͱ͖Δ func issuesStream() -> AsyncThrowingStream<[Issue], Error> { ... } do { for try await issues in issuesStream() { let myIssues = issues.filter { $0.authorId == myId } if myIssues.isEmpty { print("No issues") continue } print(myIssues) } } catch { print(error) }

Slide 17

Slide 17 text

"TZOD4FRVFODFͷͭ͘Γ͔ͨᶃ "TZOD*UFSBUPS1SPUPDPM "TZOD4FRVFODFͷ࣮૷ struct IssuesIterator: AsyncIteratorProtocol { typealias Element = [Issue] mutating func next() async throws -> [Issue]? { ... } } struct IssuesStream: AsyncSequence { typealias AsyncIterator = IssuesIterator typealias Element = [Issue] func makeAsyncIterator() -> IssuesIterator { ... } } let stream = IssuesStream()

Slide 18

Slide 18 text

"TZOD4FRVFODFͷͭ͘Γ͔ͨᶄ "TZOD4USFBN "TZOD5ISPXJOH4USFBNͰ؆୯ʹ import CloudFirestore let stream = AsyncThrowingStream([Issue].self) { continuation in let listener = Firestore.firestore().collection(“issues”) .addSnapshotListener { snapshot, error in if let error { continuation.finish(throwing: error) return } let issues = snapshot?.documents?.map(Issue.init) ?? [] continuation.yield(issues) } continuation.onTermination = { _ in listener.remove() } }

Slide 19

Slide 19 text

"TZOD4FRVFODFͷͭ͘Γ͔ͨᶅ "TZOD4USFBNNBLF4USFBN let (keywordStream, continuation) = AsyncStream.makeStream(of: String.self) Task { for await keyword in keywordStream { print(keyword) } } continuation.yield("keyword1") continuation.yield("keyword2")

Slide 20

Slide 20 text

"TZOD4FRVFODFͷࠔΓ͝ͱ 3Y4XJGU΍$PNCJOFͷ୅ସͱͯ͠͸ػೳෆ଍ʁ w ඇಉظγʔέϯεʹ஋Λૹ৴͢ΔTVCKFDU w ෳ਺ͷඇಉظγʔέϯεΛ૊Έ߹ΘͤΔDPNCJOF [JQ NFSHF w ඇಉظγʔέϯεͷ࣌ؒ࣠ʹ͓͚ΔEFCPVODF UISPUUMF w ಉ͡ඇಉظγʔέϯεΛڞ༗͢ΔTIBSF SFQMBZ NVMUJDBTU 👌

Slide 21

Slide 21 text

🤗͜Μʹͪ͸ "TZOD"MHPSJUINT

Slide 22

Slide 22 text

BQQMFTXJGUBTZODBMHPSJUINT https://github.com/apple/swift-async-algorithms

Slide 23

Slide 23 text

BQQMFTXJGUBTZODBMHPSJUINT https://github.com/apple/swift-async-algorithms

Slide 24

Slide 24 text

·ͱΊ

Slide 25

Slide 25 text

·ͱΊ 3Y4XJGU΍$PNCJOFͷ୅ସͱͯ͠"TZOD4FRVFODFਪ͍ͨ͠ʂ w 4XJGUͷݴޠػೳͰ͋Δ w ඇಉظγʔέϯεͰγϯϓϧͳߏ଄Խϓϩάϥϛϯά͕Ͱ͖Δ w ΦʔϓϯιʔεʴΫϩεϓϥοτϑΥʔϜͰ͋Δ w "QQMFͷϑϨʔϜϫʔΫͰͷରԠ͕ਐΜͰ͍Δ w "QQMFެࣜύοέʔδʹΑΔػೳ֦ு͕͋Δ w ඇಉظγʔέϯεΛڞ༗͢Δ͜ͱ͕Ͱ͖ͳ͍ͷ͕೉఺