The simplest Signal<T> implementation for Functional Reactive Programming you will ever find.
This library does not use the term FRP (Functional Reactive Programming) in the way it was defined by Conal Elliot, but as a paradigm that is both functional and reactive. Read more about the difference at Why I cannot say FRP but I just did.
- Lightweight, simple, cross plattform FRP
- Multithreading with GCD becomes a breeze
- Most of your methods will conform to the needed syntax anyway.
- Swift 2 compability
- Multithreading with GCD becomes a breeze via WarpDrive
- iOS 7.0+ / Mac OS X 10.9+
- Xcode 7
For a full guide on how this implementation works the the series of blog posts about Functional Reactive Programming in Swift or the talk at UIKonf 2015 How to use Functional Reactive Programming without Black Magic.
let text = Signal<String>()
text.next { string in
print("Hello \(string)")
}
text.update(.Success("World"))let text = Signal<String>()
let greeting = text.map { subject in
return "Hello \(subject)"
}
greeting.next { text in
print(text)
}
text.update(.Success("World"))let text = Signal<String>()
let greet: String->String = { subject in
return "Hello \(subject)"
}
text.map(greet).next { text in
print(text)
}
text.update(.Success("World"))let text = Signal<String>()
func greetMaybe(subject: String)->Result<String> {
if subject.characters.count % 2 == 0 {
return .Success("Hello \(subject)")
} else {
let error = NSError(domain: "Don't feel like greeting you.", code: 401, userInfo: nil)
return .Error(error)
}
}
text.flatMap(greetMaybe)
.next { text in
print(text)
}
.error { error in
print("There was a greeting error")
}
text.update(.Success("World"))let text = Signal<String>()
func greetMaybe(subject: String, completion: Result<String>->Void) {
if subject.characters.count % 2 == 0 {
completion(.Success("Hello \(subject)"))
} else {
let error = NSError(domain: "Don't feel like greeting you.", code: 401, userInfo: nil)
completion(.Error(error))
}
}
text.flatMap(greetMaybe)
.next { text in
print(text)
}
.error { error in
print("There was a greeting error")
}
text.update(.Success("World"))- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
Dynamic frameworks on iOS require a minimum deployment target of iOS 8 or later.
To use Interstellar with a project targeting iOS 7, you must include all Swift files directly in your project.
CocoaPods is a dependency manager for Cocoa projects.
CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:
$ gem install cocoapodsTo integrate Interstellar into your Xcode project using CocoaPods, specify it in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Interstellar'Then, run the following command:
$ pod installCarthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthageTo integrate Interstellar into your Xcode project using Carthage, specify it in your Cartfile:
github "JensRavens/Interstellar"
Interstellar is meant to be lightweight. There are no UIKit bindings, no heavy constructs - just a simple Signal<T>. Therefore it's easy to understand and portable (there is no dependency except Foundation).
Interstellar is owned and maintained by Jens Ravens.
- 1.1 added compability with Swift 2. Also renamed bind to flatMap to be consistent with
OptionalandArray. - 1.2
Threadwas moved to a new project called WarpDrive - 1.3 WarpDrive has been merged into Interstellar. Also Interstellar is now divided into subspecs via cocoapods to make it easy to just select the needed components. The basic signal library is now "Interstellar/Core".
Interstellar is released under the MIT license. See LICENSE for details.
