Skip to content

👜 A standard for Swift callbacks that enables lightweight observables and iterables

License

Notifications You must be signed in to change notification settings

chuthin/Callbag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Callbag

CI Status Version License Platform

This is an implemented Callbag protocol founded by André Staltz in Swift.

Specification

  Talkback  = (_ payload:Any?) -> Void
  Sink<T>   = (_ payload:Payload<T>) -> Void
  Source<T> = (_ sink:Sink<T>) -> Void;

Functions have been implemented

Factories

  • fromArray
  • fromInterval
  • fromSubject
  • makeReplaySubject
  • makeSubject
  • create
  • empty
  • never

Sink factories

  • subscribe

Operators

  • map
  • flatmap
  • filter
  • take
  • first
  • skip
  • last
  • scan
  • merge
  • combine

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
       => subscribe{ print($0)}
        
    //4
    //8
    //12
    //16

Installation

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

pod 'Callbag'

References

About

👜 A standard for Swift callbacks that enables lightweight observables and iterables

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published