|
| 1 | +[](https://travis-ci.org/typelift/Swiftx) |
| 2 | + |
| 3 | +Swiftx |
| 4 | +====== |
| 5 | + |
| 6 | +Swiftx is a Swift library containing functional abstractions and extensions to |
| 7 | +the Swift Standard Library. Swiftz Core is a smaller and simpler way to introduce pure functional |
| 8 | +datatypes into any codebase. |
| 9 | + |
| 10 | +Setup |
| 11 | +----- |
| 12 | + |
| 13 | +Swiftx can be included one of two ways: |
| 14 | + |
| 15 | +**Framework** |
| 16 | + |
| 17 | +- Drag `Swiftx.xcodeproj` or `Swiftx-iOS.xcodeproj` into your project tree as a subproject |
| 18 | +- Under your project's Build Phases, expand Target Dependencies |
| 19 | +- Click the + and add Swiftx |
| 20 | +- Expand the Link Binary With Libraries phase |
| 21 | +- Click the + and add Swiftx |
| 22 | +- Click the + at the top left corner to add a Copy Files build phase |
| 23 | +- Set the directory to `Frameworks` |
| 24 | +- Click the + and add Swiftx |
| 25 | + |
| 26 | +**Standalone** |
| 27 | + |
| 28 | +- Copy the swift files under `Swiftx/Swiftx` into your project. |
| 29 | + |
| 30 | +Introduction |
| 31 | +------------ |
| 32 | + |
| 33 | +Swiftx provides a number of common data types and abstractions any codebase can utilize. |
| 34 | + |
| 35 | +A small example: |
| 36 | + |
| 37 | +```swiftz |
| 38 | +import Swiftx |
| 39 | +
|
| 40 | +let str : String? = .Some("Hello ") |
| 41 | +let greeting = (+"World") <^> str // .Some("Hello World") |
| 42 | +``` |
| 43 | + |
| 44 | +Seamless interaction with existing platform libraries is also possible with |
| 45 | +minimal effort: |
| 46 | + |
| 47 | +```swiftz |
| 48 | +import Foundation |
| 49 | +import struct Swiftx.Result |
| 50 | +
|
| 51 | +/// result now contains either an array of file paths or the error generated by `NSFileManager`. |
| 52 | +let result : Result<[String]> = from({ ep in |
| 53 | + let documentsDirectory : String = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String) |
| 54 | + return (NSFileManager.defaultManager().contentsOfDirectoryAtPath(documentsDirectory, error: ep) as [String]?) ?? [] |
| 55 | +}) |
| 56 | +``` |
| 57 | + |
| 58 | + |
| 59 | +Swiftx can even help with expressions of nothingness or errors: |
| 60 | + |
| 61 | +```swiftz |
| 62 | +import Swiftx |
| 63 | +
|
| 64 | +/// We may not be able to do what we said we'd do, but this definition compiles. At runtime, |
| 65 | +/// any code that invokes this function will immediately halt the program. |
| 66 | +func provePEqualsNP() -> Proof<P, NP> { |
| 67 | + return undefined() |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +System Requirements |
| 72 | +=================== |
| 73 | + |
| 74 | +Swiftz and Swiftz Core support OS X 10.9+ and iOS 7.0+. |
| 75 | + |
| 76 | +License |
| 77 | +======= |
| 78 | + |
| 79 | +Swiftx is released under the BSD license. |
| 80 | + |
0 commit comments