Functional data types and functions for any project

Overview

Swiftx

Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way to introduce pure functional datatypes into any codebase.

For a more full-featured library checkout Swiftz.

Setup

Swiftx can be included one of two ways:

Framework

  • Drag Swiftx.xcodeproj or Swiftx-iOS.xcodeproj into your project tree as a subproject
  • Under your project's Build Phases, expand Target Dependencies
  • Click the + and add Swiftx
  • Expand the Link Binary With Libraries phase
  • Click the + and add Swiftx
  • Click the + at the top left corner to add a Copy Files build phase
  • Set the directory to Frameworks
  • Click the + and add Swiftx

Standalone

  • Copy the swift files under Swiftx/Swiftx into your project.

Introduction

Swiftx provides a number of common data types and abstractions any codebase can utilize.

A small example:

import Swiftx

let str : String? = .Some("Hello ")
let greeting = (+"World") <^> str // .Some("Hello World")

Seamless interaction with existing platform libraries is also possible with minimal effort:

import Foundation
import struct Swiftx.Result

/// result now contains either an array of file paths or the error generated by `NSFileManager`.
let result : Result<[String]> = from({ ep in
    let documentsDirectory : String = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String)
    return (NSFileManager.defaultManager().contentsOfDirectoryAtPath(documentsDirectory, error: ep) as [String]?) ?? []
})

Swiftx can even help with expressions of nothingness or errors:

import Swiftx

/// We may not be able to do what we said we'd do, but this definition compiles. At runtime, 
/// any code that invokes this function will immediately halt the program.
func provePEqualsNP() -> Proof<P, NP> {
    return undefined()
}

System Requirements

Swiftx supports OS X 10.9+ and iOS 8.0+.

License

Swiftx is released under the BSD license.

Comments
  • Should Operadics be in `Cartfile.private`?

    Should Operadics be in `Cartfile.private`?

    Operadics seems necessary to build Swiftx but is not pulled down by carthage update when I depend on Swiftx from a mac project. If I cd into /Carthage/Checkouts/Swiftx and then run carthage bootstrap, I can then get the mac app to run carthage update successfully but codesign fails.

    Failure aside, it looks as though Cartfile.private should be used for dependencies that aren't necessarily useful in release but that doesn't look like a fitting description of Operadics

    opened by griotspeak 13
  • Consider giving the Y-combinator, `fix`, two type parameters.

    Consider giving the Y-combinator, `fix`, two type parameters.

    Currently fix is defined so:

    public func fix<A>(f : ((A -> A) -> A -> A)) -> A -> A {
        return { x in f(fix(f))(x) }
    }
    

    I have found the following fix more useful:

    public func fix<T, U>(f: (T -> U) -> T -> U) -> T -> U {
        return { x in f(fix(f))(x) }
    }
    

    Could this act as a replacement, or addition, to the current fix?

    cheers,

    Daniel

    opened by DanielAsher 6
  • Initial port to Swift 4

    Initial port to Swift 4

    What's in this pull request?

    Initial migration of library to Swift 4. (Minor changes but lib required by Swiftz which has more extensive changes)

    Why merge this pull request?

    Migrates library to latest version of Swift. All tests passing with the Swift 4 version of SwiftCheck that I submitted as a PR earlier.

    What's worth discussing about this pull request?

    This PR focuses on getting the build compiling without warning and passing all tests. I will have missed anything not picked up by these! There may be some wider changes you have in mind to take advantage of Swift 4.

    What downsides are there to merging this pull request?

    Uses temporary refs to my personal SwiftCheck forks with Swift 4 migration. Will need updating to point to official SwiftCheck repos.

    opened by tcldr 4
  • Consider updating SwiftCheck dependency to `swift-develop` branch

    Consider updating SwiftCheck dependency to `swift-develop` branch

    Swiftx swift-development branch a2329bc9503b22527514bcec9bff7b9906505fdf has submodule SwiftCheck currently pinned here: d45d7023fa93c51292079c159ff18aa0c1cf5269

    Can this be updated to the latest SwiftCheck swift-develop branch, here 354140578a6deab234604e298c76e262ad456f6e?

    It's currently rather confusing that the SwiftCheck master branch shows the old subscript syntax for properties.

    thanks,

    Daniel

    opened by DanielAsher 3
  • Minor fixes to Xcode project file

    Minor fixes to Xcode project file

    Updated path to Operators.swift file to reflect revised location in third-party library Updated Xcode group name to 'Sources' to reflect actual directory layout

    opened by tcldr 2
  • Can't assign result of pipe operator

    Can't assign result of pipe operator

    func f(x: Int) -> Int {
        return 0
    }
    
    var x = 0
    x = 5 |> f // error
    

    Since the precedence group has no order relationship with AssignmentPrecedence:

    precedencegroup LeftAssociativeCombinatorPrecedence {
        associativity: left
        lowerThan: DefaultPrecedence
    }
    

    Is this intended behaviour? Before Swift 3, we had precedence 95 which is lower than ternary operator (100) and higher than assignment (90).

    opened by CosynPa 2
  • Updating <*>

    Updating <*>

    Original:

    public func <*> <A, B>(f : (A -> B)?, a : A?) -> B? {
        return f.flatMap({ a.map($0) })
     }
    

    What do you think about updating it so that it uses <^>?

    New:

    public func <*> <A, B>(f : (A -> B)?, a : A?) -> B? {
        return f.flatMap { $0 <^> a }
     }
    
    opened by mpurland 2
  • Remove Result

    Remove Result

    With Swift 2.0 introducing exceptions to take the place of NSErrorPointer-style functions, and the advent of ErrorType, Result's days are numbered. I propose we remove it entirely, as it can be replicated with Either<ErrorType, B>.

    enhancement question 
    opened by CodaFi 2
  • Xcode 10 Compatibility

    Xcode 10 Compatibility

    It's a bit late for me to dig in further, but the following directive seems to be getting tripped up in Xcode 10.

    #if SWIFT_PACKAGE
      import Operadics
    #endif
    

    Reproduce:

    1. Run sudo xcode select --switch /Applications/Xcode-beta.app/ where Xcode-beta.app is the first Xcode 10 WWDC beta.
    2. Run swift package generate-xcodeproj against a project using Swiftx, e.g. https://github.com/bkase/DoctorPretty
    3. Try to build the project.

    It'll fail because Operadics isn't being imported, I assume because #if SWIFT_PACKAGE is false.

    opened by stephencelis 1
  • CocoaPods: Files from Swiftx/Source/*.swift are not being downloaded

    CocoaPods: Files from Swiftx/Source/*.swift are not being downloaded

    Hi,

    Yesterday I created an issue regarding the update of the PodSpec of this project. Thanks for your quick assistance!

    Regarding that, today I added it to my Podfile. However, It seems that, even if the PodSpec specifies the Swiftx/Source/*.swift source files, they are note being downloaded to my machine and just the Carthage folder remains.

    My Podfile:

    platform :ios, '8.0'
    
    target 'MYTARGET' do
      use_frameworks!
    
      pod 'Action'
      pod "Aspects"
      pod "AsyncSwift"
      pod 'CocoaLumberjack/Swift'
      pod 'Cartography'
      pod 'Curry'
      pod 'KeychainAccess'
      pod 'Kingfisher'
      pod 'Moya/RxSwift', '~> 8.0'
      pod 'NSDate-Escort'
      pod 'NSObject+Rx'
      pod 'R.swift'
      pod 'Runes'
      pod 'RxSwift', '~> 3.0'
      pod 'SegueManager/R.swift'
      pod 'SugarRecord', '~> 3.0'
      pod 'RxSugarRecord/Realm'
      pod 'Swiftx'
      pod 'SwiftyJSON'
      pod 'SwiftyUserDefaults'
      pod 'SWRevealViewController'
      pod 'Then', '~> 2.1'
      pod 'TTTAttributedLabel'
      pod 'Fabric'
      pod 'Crashlytics'
    
    end
    

    Thanks in advance!

    opened by AlexTanabe 1
Releases(0.8.0)
Owner
TypeLift
Libraries to simplify development of Swift programs by utilising the type system.
TypeLift
Functional programming tools and experiments in Swift.

Funky The documentation (courtesy of realm/jazzy) is available here: https://brynbellomy.github.io/Funky Master branch is currently compatible with: S

Bryn Bellomy 12 May 2, 2017
A set of Swift extensions for standard types and classes.

ExSwift Set of Swift extensions for standard types and classes. Installation Because of Xcode errors it's not possible to integrate this project with

Pierluigi D'Andrea 3.4k Dec 27, 2022
Collection of must-have functional Swift tools

NOTE: This project has been merged with and superceded by Rob Rix's Result µframework. LlamaKit Collection of must-have functional tools. Trying to be

null 619 Aug 5, 2022
A functional utility belt implemented as Swift 2.0 protocol extensions.

Oriole [![CI Status](http://img.shields.io/travis/Tyler Thompson/Oriole.svg?style=flat)](https://travis-ci.org/Tyler Thompson/Oriole) Oriole is a set

Tyler Paul Thompson 11 Aug 10, 2019
Swift µframework of simple functional programming tools

Prelude This is a Swift µframework providing a number of simple functions that I use in many of my other frameworks. Rather than continue to reimpleme

Rob Rix 405 Jun 29, 2022
Functional programming in Swift

Swiftz Swiftz is a Swift library for functional programming. It defines functional data structures, functions, idioms, and extensions that augment the

TypeLift 3.3k Dec 25, 2022
Functional JSON parsing library for Swift

Argo Argo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend. Using Argo

thoughtbot, inc. 3.5k Jan 7, 2023
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift

Bow is a cross-platform library for Typed Functional Programming in Swift. Documentation All documentation and API reference is published in our websi

Bow 613 Dec 20, 2022
Functional programming in Swift

Swiftz Swiftz is a Swift library for functional programming. It defines functional data structures, functions, idioms, and extensions that augment the

TypeLift 3.3k Jan 6, 2023
Infix operators for monadic functions in Swift

Indecipherable symbols that some people claim have actual meaning. Please see the documentation for installation instructions. What's included? Import

thoughtbot, inc. 825 Dec 7, 2022
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

TypeLift 219 Aug 30, 2022
An experimental functional programming language with dependent types, inspired by Swift and Idris.

Kara An experimental functional programming language with dependent types, inspired by Swift and Idris. Motivation Development of Kara is motivated by

null 40 Sep 17, 2022
Keep It Functional - An iOS Functional Testing Framework

IMPORTANT! Even though KIF is used to test your UI, you need to add it to your Unit Test target, not your UI Test target. The magic of KIF is that it

KIF Framework 6.2k Dec 29, 2022
Metron is a comprehensive collection of geometric functions and types that extend the 2D geometric primitives

Metron Geometry, simplified. Metron is a comprehensive collection of geometric functions and types that extend the 2D geometric primitives provided by

Toine Heuvelmans 1k Dec 5, 2022
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Mathias Quintero 9 Sep 25, 2022
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
AutoMocker is a Swift framework that leverages the type system to let you easily create mocked instances of your data types.

AutoMocker Context AutoMocker is a Swift framework that leverages the type system to let you easily create mocked instances of your data types. Here's

Vincent Pradeilles 39 May 19, 2022
ServiceData is an HTTP networking library written in Swift which can download different types of data.

ServiceData Package Description : ServiceData is an HTTP networking library written in Swift which can download different types of data. Features List

Mubarak Alseif 0 Nov 11, 2021
Lightweight Framework for using Core Data with Value Types

Features Uses Swift Reflection to convert value types to NSManagedObjects iOS and Mac OS X support Use with structs Works fine with let and var based

Benedikt Terhechte 456 Nov 6, 2022