Skip to content

Instantly share code, notes, and snippets.

@53ningen
Last active August 29, 2015 14:22
Show Gist options
  • Save 53ningen/d5ab8148bdf1aa88b55a to your computer and use it in GitHub Desktop.
Save 53ningen/d5ab8148bdf1aa88b55a to your computer and use it in GitHub Desktop.

RxSwift はじめのいっぽ

RxSwift を使う機会があったため、その挙動がとりあえず、なんとなくわかるようなコードをまとめておきます。

import Quick
import Nimble
import RxSwift

class CollectionsSpec: QuickSpec {
    override func spec() {
        describe("RxSwift") {
            it("manipulate collections1") {
                let nums = from([1,2,3,4,5,6,7,8,9,10])
                    >- filter { $0 > 8 }
                    >- subscribeNext { println($0) }
                // Outputs:
                // 9
                // 10
            }
            it("manipulate collections2") {
                let nums = from([1,2,3,4,5,6,7,8,9,10])
                    >- filter { $0 > 8 }
                    >- map { $0 + 10 }
                    >- subscribeNext { println($0) }
                // Outputs:
                // 19
                // 20
            }       
        }
    }  
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment