To run the example project, clone the repo, and run pod install
from the Example directory first.
- You can use this instead of condition statement according to functional programming paradigm.
- Ensures thread safety.
- It is simple.
- Global variable.
if <<true or false>> {
} else if <<true or false>> {
} else {
}
_if(<<true or false>>) {}
.elseif(<<true or false>>) {}
.else {}
if <<true or false>> {
} else if <<true or false>> {
} else {
}
if <<true or false>> {
} else if <<true or false>> {
} else {
}
_if(<<true or false>>) {}
.elseif(<<true or false>>) {}
.else {}
.if(<<true or false>>) {}
.elseif(<<true or false>>) {}
.else {}
- Here are some frequently used functions with array.
// Sample struct
struct Model: Hashable {
let uid: String
var hashValue: Int { return uid.hashValue }
static func ==(lhs: Model, rhs: Model) -> Bool {
return lhs.uid == rhs.uid
}
}
let source = ["A", "A", "B", "C"]
let grouped = source.grouped { $0 }
// print -> ["A": ["A", "A"], "B": ["B"], "C": ["C"]]
let source = [Model(uid: "A"), Model(uid: "A"), Model(uid: "B"), Model(uid: "C")]
let grouped = source.grouped { $0.uid }
// print -> ["A": [Model(uid: "A"), Model(uid: "A")], "B": [Model(uid: "B")], "C": [Model(uid: "C")]]
let source = [Model(uid: "A"), Model(uid: "B")]
let other = [Model(uid: "A")]
let subtracted = source.subtracted(other)
// print -> [Model(uid: "B")]
let source = [Model(uid: "A"), Model(uid: "A"), Model(uid: "B"), Model(uid: "B")]
let uniqued = source.uniqued()
// print -> [Model(uid: "A"), Model(uid: "B"), Model(uid: "C")]
- You can use unwrap of Optional instead of map when you don't need return element.
import FunctionalSwiftKit
func testUnwrap() {
let string: String? = "string"
string.unwrap { <<your function for execution>>($0) }
}
func testEmpty() {
let string: String? = "string"
string
.map { print($0) }
.empty { print("empty") }
}
iOS Deployment Target 9.0 higher
FunctionalSwiftKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'FunctionalSwiftKit'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate FunctionalSwiftKit into your Xcode project using Carthage, specify it in your Cartfile
:
github "pisces/FunctionalSwiftKit"
Run carthage update
to build the framework and drag the built FunctionalSwiftKit.framework
into your Xcode project.
Steve Kim, [email protected]
FunctionalSwiftKit is available under the BSD 2-Clause License license. See the LICENSE file for more info.