Latest 0.2.3
Homepage https://github.com/chuthin/Callbag
License MIT
Platforms ios 10.0
Authors

CI Status
Version
License
Platform

This is an attempt to build Callbag protocol founded by André Staltz in Swift.

Specification

(Payload<T>) -> Void

Payload is sum type (start|data|end)

Functions have been implemented

Source factories

  • fromValues
  • fromArrays
  • fromInterval
  • fromEvent
  • textFrom

    Sink factories

  • forEach

    Transformation operators

  • map
  • filter
  • take
  • takeUntil
  • skip
  • skipUntil
  • scan
  • startWith

    Combination operators

  • merge
  • combineLastest

    Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Reactive programming examples

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
       *> forEach{ print($0)}

    //4
    //8
    //12
    //16

Counter

public class CounterViewController : UIViewController {
    @IBOutlet weak var incrementButton: UIButton!
    @IBOutlet weak var decrementButton: UIButton!
    @IBOutlet weak var counterLabel: UILabel!
    public override func viewDidLoad() {
        super.viewDidLoad()
        let increment = fromEvent(incrementButton, .touchUpInside) *> map { _ in 1}
        let decrement = fromEvent(decrementButton, .touchUpInside) *> map { _ in -1}

        merge(increment,decrement)
            *> scan(0){ $0 + $1}
            *> forEach {[weak self] value in
                self?.counterLabel.text = String(value)
        }
    }
}

Requirements

Callbag is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Callbag'
pod 'CallbagCocoa'

References

Callbag is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Callbag",
    "version": "0.2.3",
    "summary": "An implement Callbag.js",
    "description": "An implement Callbag.js with Swift",
    "homepage": "https://github.com/chuthin/Callbag",
    "license": "MIT",
    "authors": {
        "Chu Thin": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/chuthin/Callbag.git",
        "tag": "0.2.3"
    },
    "source_files": "Callbag/**/*.{swift}"
}

Pin It on Pinterest

Share This