Latest 0.1.0
Homepage https://github.com/Weebly/FunKit
License MIT
Platforms ios 9.0

master
develop
Documentation
CocoaPods

Pipelines. Promises. Railways. Your way.

FunKit is a functional toolkit for Swift. It integrates railway-oriented programming with promises, providing a novel way to build Swift applications.

enum App {

    static func main(context: AppContext) -> Bool {

        func addOKAction(alert: UIAlertController) {
            (title: "OK", style: .default, handler: nil)
                |> UIAlertAction.init
                |> alert.addAction
        }

        let showAlert = UIAlertController.init(title:message:preferredStyle:)
            >>> tee(addOKAction)
            >>> curry(reverse(context.viewController.present))(nil)(true)

        func success<A>(_: A) {
            (title: "Initialized", message: nil, preferredStyle: .alert)
                |> showAlert
        }

        func failure(error: Error) {
            (title: "Failed", message: error.localizedDescription, preferredStyle: .alert)
                |> showAlert
        }

        func done() { print("Initialization complete") }

        func returnTrue<A>(_: A) -> Bool { return true }

        return ()
            |> context.initialize
            |> Promise.main
            ?> success
            !> failure
            *> done
            |> returnTrue
    }

}

Pipelines

Pipelines let you build functions like shell commands, where the output of one function is the input of another. This reduces the need for temporary variables while maintaining readability, using the |> operator. The compose operator (>>>) can be used to build pipeline functions, when there isn’t a value to feed into it right away.

Railways

Railways improve upon pipelines by allowing methods to return a value denoting some sort of error condition. Traditional functions can be adapted using turnout, removing the need to manually check for errors at every step.

The unwrap function converts nil values to failures, while tryCatch does the same for thrown Errors.

Promises

Promises are considered asynchronous railways. They can be created directly from railway Results, or fulfilled or rejected asynchronously. Syntactic sugar operators such as ?>, !>, and *> make it easy to integrate promises with pipelines and railways.

Lazy Evaluation

FunKit makes extensive use of @autoclosure in an effort to provide lazy evaluation. However, the performance impacts have not been looked into.

Latest podspec

{
    "name": "FunKit",
    "version": "0.1.0",
    "summary": "A Functional Toolkit for Swift.",
    "description": "FunKit integrates railway-oriented programming with promises, providing a novel way to build Swift applications.",
    "homepage": "https://github.com/Weebly/FunKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "jacob berkman",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/Weebly/FunKit.git",
        "tag": "v0.1.0"
    },
    "source_files": "FunKit/*.swift",
    "pushed_with_swift_version": "3.2"
}

Pin It on Pinterest

Share This