Functional data types and functions for any project

Related tags

Utility Swiftx
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
Measure the power output from a car or any moving vehicle from GPS data and weight

GPSDyno Measure the power output from a car or any moving vehicle from weight and GPS data of your iOS device. This is just a example project and shou

Marcelo Ferreira Barreto 0 Jan 7, 2022
A lightweight extension to Swift's CollectionDifference, supporting moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

DifferenceTracker is a lightweight extension to Swift's CollectionDifference. It defines moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

Giles Hammond 2 Nov 25, 2022
How Swift standard types and classes were supposed to work.

How Swift standard types and classes were supposed to work. A collection of useful extensions for the Swift Standard Library, Foundation, and UIKit.

Goktug Yilmaz 3k Dec 22, 2022
Swift package adding fraction and percentage types.

swift-rationals Rationals is a package containing Fraction and Percentage types for the Swift programming language. Contents The package currently pro

Alexandre H. Saad 0 Jul 28, 2022
Parsing indeterminate types with Decodable and Either enum using Swift

Decodable + Either Parsing indeterminate types with Decodable and Either enum us

Alonso Alvarez 1 Jan 9, 2022
Extensions for Swift Standard Types and Classes

Cent Cent is a library that extends certain Swift object types using the extension feature and gives its two cents to Swift language. Dollar is a Swif

Ankur Patel 225 Dec 7, 2022
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

David Roman 3 Oct 14, 2022
🏹 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
A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript

Dollar Dollar is a Swift library that provides useful functional programming helper methods without extending any built in objects. It is similar to L

Ankur Patel 4.2k Jan 2, 2023
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
Recreating a fully functional version of iOS 4 in SwiftUI.

Updates: Version 1.0 is currently available ?? While I work on fixing an issue in Xcode 12.5+ with LazyVGrid, I recommend you build using Xcode 12.4 a

null 2.9k Jan 1, 2023
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
A set of helper classes and functions in Swift

SwiftTools This is a set of tools written in Swift that add some sugar and some small functionality. Mainly meant for small projects and scripts, as a

Vinicius Vendramini 0 Dec 13, 2021
Utility functions for validating IBOutlet and IBAction connections

Outlets Utility functions for validating IBOutlet and IBAction connections. About Outlets provides a set of functions which validate that IBOutlets ar

Ben Chatelain 129 May 2, 2022
Useful functions and extensions for sorting in Swift

SwiftSortUtils Motivation This library takes a shot at making comparing and sorting in Swift more pleasant. It also allows you to reuse your old NSSor

Daniel Strittmatter 60 Sep 9, 2022
The ISO 8601 period/duration types missing in Foundation

PeriodDuration This library introduces a close equivalent to Java's PeriodDuration, motivated by the lack of support for this standard in Foundation.

David Roman 19 Jun 22, 2022
Numerals is a package containing additional numeric types for the Swift programming language.

swift-numerals Numerals is a package containing additional numeric types for the Swift programming language. Contents The package currently provides t

Alexandre H. Saad 0 Jul 28, 2022
Swift package adding measurable types.

swift-measures Measures is a package containing measurable types for the Swift programming language. Contents The package currently provides the follo

Alexandre H. Saad 1 Nov 5, 2022