Latest 0.0.2
Homepage https://github.com/HCA-Healthcare/FunctionalSwift
License APACHE 2.0
Platforms ios 10.0

FunctionalSwift

Version
License
Platform
Carthage compatible
Swift 4.2

Hey! Welcome to FunctionalSwift this the framewrok we are using here at HCA for adopting funcitonal style programming using the Swift language.

Table Of Contents
Installation
Usage
Contributing
License

Installation

Carthage

If you are using Carthage, add the following lines to your Cartfile:

github "HCAHealthcare/FunctionalSwift" ~> 0.0.2

Then run carthage bootstrap.

For more information about Carthage usage, check their official documentation.

Cocoapods

If you are using Cocoapods, add these lines to your Podfile:

use_frameworks!
pod 'FxSwift', '~> 0.0.2'

Then, run pod install.

For further reference on Cocoapods, check their official documentation.

Usage

First you will need to import the framework

import FunctionalSwift

Common Operators

Forward Application |>

Pipes data into a function

Example:

let result = "String Data" 
|> stringToResult

Backward Application <|

Pipes data into a function

Example:

let utf8String =  flip(curry(String.init(data:encoding:)))
<| .utf8

Single Type Composition <>

Composes two functions that return the same type

Example:

let backgroundViewStyle = set(UIView.backgroundColor, .white) 
<> set(UIView.translatesAutoresizingMaskIntoConstraints, false)

Foward Composition >>>

Composes two functions that return the same or different types

Example:

let isSuccess = utf8String         // Data -> String
>>> boolValue  // String -> Bool

let result = dataResponse
|> isSuccess

Common Functions

curry

Transforms a function with multiplt inputs into a pure funcition that chains the inputs into returned functions.

Example:

let stringFromData = String.init(data:encoding)   // (Data, String.Encoding) -> String?
let curriedStringFromData = curry(stringFromData) // (Data) -> (String.Encoding) -> String?

flip

Is often used with curry. Flip swaps the order in which the curried inputs are executed

Example:

let stringFromData = String.init(data:encoding)         // (Data, String.Encoding) -> String?
let curriedStringFromData = curry(stringFromData)       // (Data) -> (String.Encoding) -> String?
let flippedStringFromData = flip(curriedStringFromData) // (String.Encoding) -> (Data) -> String?
let utf8String = .utf8 |> flippedStringFromData         // (Data) -> String?

set

Set uses Swift’s Keypaths to go into a Root type and sets over the given path and returns a copy of the orginial Root value

Example:

let backgroundView = self.view
|> set(UIView.backgroundColor, .white)                          //Root => UIView, Path => UIColor
<> set(.translatesAutoresizingMaskIntoConstraints, false)       //Root => UIView, Path => Bool

Contributing

We welcome all contributions please submit a pull request, if you run into any issues please create an issue.

License

This project is licensed under the Apache 2.0 license. Please see License for more information

Latest podspec

{
    "name": "FxSwift",
    "version": "0.0.2",
    "summary": "FxSwift brings functional concepts to the Swift language with standard functions and operators",
    "description": "FxSwift brings functional concepts to the Swift language with standard functions and operators",
    "homepage": "https://github.com/HCA-Healthcare/FunctionalSwift",
    "license": {
        "type": "APACHE 2.0",
        "file": "LICENSE"
    },
    "authors": "HCA Healthcare",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/HCA-Healthcare/FunctionalSwift.git",
        "tag": "0.0.2"
    },
    "source_files": "Sources/FunctionalSwift/*.swift"
}

Pin It on Pinterest

Share This