This is an implemented Callbag protocol founded by AndrΓ© Staltz in Swift.
Talkback = (_ payload:Any?) -> Void
Sink<T> = (_ payload:Payload<T>) -> Void
Source<T> = (_ sink:Sink<T>) -> Void;
- fromArray
- fromInterval
- fromSubject
- makeReplaySubject
- makeSubject
- create
- empty
- never
- subscribe
- map
- flatmap
- filter
- take
- first
- skip
- last
- scan
- merge
- combine
To run the example project, clone the repo, and run pod install
from the Example directory first.
Pick the first 5 odd numbers from a clock that ticks every second, then start observing them:
fromInterval(1)
=> map{ $0 1}
=> filter{ $0 % 2 != 0}
=> take(5)
=> forEach{ print($0)}
//1
//3
//5
//7
//9
From a array
fromArray([1,2,3,4,5,6,7,8,9]) // 1, 2, 3, 4, 5, 6, 7, 8, 9,
=> filter{ $0 % 2 == 0} // 2, 4, 6, 8
=> map { $0 * 2} // 4, 8, 12, 16
=> subscribe{ print($0)}
//4
//8
//12
//16
Callbag is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Callbag'