swiftf
swiftf provides some higher-order methods for Optional
.
Usage
Optional
forEach
let a: Int? = 2
let b: Int? = nil
a.forEach { print($0) } // 2
b.forEach { print($0) } // prints nothing
filter
let a: Int? = 2
let b: Int? = 3
let c: Int? = nil
a.filter { $0 % 2 == 0 } // Optional(2)
b.filter { $0 % 2 == 0 } // nil
c.filter { $0 % 2 == 0 } // nil
reduce
let name1: String? = "world"
let name2: String? = nil
let r1: String = name1.reduce("Hello") { $0 + ", " + $1} // Hello, world
let r2: String = name2.reduce("Hello") { $0 + ", " + $1} // Hello
How to Install
Embedded Framework
- Put swiftf.xcodeproj into your project in Xcode.
- Click the project icon and select the "General" tab.
- Add swiftf.framework to "Embedded Binaries".
import swiftf
in your swift files.
Put swiftf.framework into your project.