├── .gitignore ├── .gitmodules ├── .swift-version ├── .travis.yml ├── Cartfile ├── Cartfile.private ├── Cartfile.resolved ├── LICENSE ├── Package.swift ├── README.md ├── Sources ├── Info.plist ├── Swiftx.h └── Swiftx │ ├── Array.swift │ ├── Combinators.swift │ ├── Either.swift │ ├── Error.swift │ └── Optional.swift ├── Swiftx.podspec ├── Swiftx.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ ├── Swiftx-iOS.xcscheme │ ├── Swiftx-tvOS.xcscheme │ ├── Swiftx-watchOS.xcscheme │ ├── Swiftx.xcscheme │ └── SwiftxTests.xcscheme └── Tests ├── Info.plist ├── LinuxMain.swift └── SwiftxTests └── EitherSpec.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | .build/* 4 | Packages/* 5 | Package.resolved 6 | build/* 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata 16 | *.xccheckout 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | *.xcuserstate 22 | *.xcscmblueprint 23 | Carthage/ 24 | 25 | # CocoaPods 26 | # 27 | # We recommend against adding the Pods directory to your .gitignore. However 28 | # you should judge for yourself, the pros and cons are mentioned at: 29 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 30 | # 31 | # Pods/ 32 | 33 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Carthage/Checkouts/SwiftCheck"] 2 | path = Carthage/Checkouts/SwiftCheck 3 | url = https://github.com/typelift/SwiftCheck.git 4 | [submodule "Carthage/Checkouts/Operadics"] 5 | path = Carthage/Checkouts/Operadics 6 | url = https://github.com/typelift/Operadics.git 7 | [submodule "Carthage/Checkouts/FileCheck"] 8 | path = Carthage/Checkouts/FileCheck 9 | url = https://github.com/trill-lang/FileCheck.git 10 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 5.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - LC_CTYPE=en_US.UTF-8 4 | matrix: 5 | include: 6 | - os: osx 7 | language: objective-c 8 | osx_image: xcode10.2 9 | before_install: 10 | - git submodule update --init --recursive 11 | script: 12 | - pod lib lint 13 | - carthage build --no-skip-current 14 | - os: osx 15 | language: objective-c 16 | osx_image: xcode10.2 17 | before_install: 18 | - git submodule update --init --recursive 19 | script: 20 | - set -o pipefail 21 | - xcodebuild test -scheme Swiftx | xcpretty -c 22 | - xcodebuild build-for-testing -scheme Swiftx-iOS -destination "platform=iOS Simulator,name=iPad Pro (12.9-inch) (2nd generation)" | xcpretty -c 23 | - xcodebuild test -scheme Swiftx-iOS -destination "platform=iOS Simulator,name=iPad Pro (12.9-inch) (2nd generation)" | xcpretty -c 24 | - xcodebuild build-for-testing -scheme Swiftx-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p)' | xcpretty -c 25 | - xcodebuild test -scheme Swiftx-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p)' | xcpretty -c 26 | - os: linux 27 | language: generic 28 | sudo: required 29 | dist: trusty 30 | before_install: 31 | - git submodule update --init --recursive 32 | - wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - 33 | - wget https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz 34 | - tar xzf swift-5.0-RELEASE-ubuntu14.04.tar.gz 35 | - export PATH=${PWD}/swift-5.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}" 36 | script: 37 | - swift build 38 | notifications: 39 | webhooks: 40 | urls: 41 | - https://webhooks.gitter.im/e/1d781e1bcbabade5de35 42 | on_success: always 43 | on_failure: always 44 | on_start: always 45 | 46 | -------------------------------------------------------------------------------- /Cartfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typelift/Swiftx/4affb6451b6981cf56c2ec1287aaee3406a5e5e0/Cartfile -------------------------------------------------------------------------------- /Cartfile.private: -------------------------------------------------------------------------------- 1 | github "typelift/Operadics" 2 | github "typelift/SwiftCheck" 3 | 4 | -------------------------------------------------------------------------------- /Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "typelift/Operadics" "0.4.0" 2 | github "typelift/SwiftCheck" "0.12.0" 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, TypeLift 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.0 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Swiftx", 7 | products: [ 8 | .library( 9 | name: "Swiftx", 10 | targets: ["Swiftx"]), 11 | ], 12 | dependencies: [ 13 | .package(url: "https://github.com/typelift/Operadics.git", from: "0.3.0"), 14 | .package(url: "https://github.com/typelift/SwiftCheck.git", from: "0.9.0"), 15 | ], 16 | targets: [ 17 | .target( 18 | name: "Swiftx", 19 | dependencies: ["Operadics"]), 20 | .testTarget( 21 | name: "SwiftxTests", 22 | dependencies: ["Swiftx", "Operadics", "SwiftCheck"]), 23 | ] 24 | ) 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Swiftx 2 | ====== 3 | 4 | Swiftx is a Swift library containing functional abstractions and extensions to 5 | the Swift Standard Library. Swiftx is a smaller and simpler way to introduce pure functional 6 | datatypes into any codebase. 7 | 8 | For a more full-featured library checkout [Swiftz](https://github.com/typelift/swiftz). 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 | ```swift 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 | ```swift 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 | ```swift 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
{
67 | return undefined()
68 | }
69 | ```
70 |
71 | System Requirements
72 | ===================
73 |
74 | Swiftx supports OS X 10.9+ and iOS 8.0+.
75 |
76 | License
77 | =======
78 |
79 | Swiftx is released under the BSD license.
80 |
81 |
--------------------------------------------------------------------------------
/Sources/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | (_ f : (R) -> Either) -> Bool {
45 | switch (lhs, rhs) {
46 | case let (.Right(l), .Right(r)) where l == r:
47 | return true
48 | default:
49 | return false
50 | }
51 | }
52 |
53 | class EitherSpec : XCTestCase {
54 | func testProperties() {
55 | property("isLeft behaves") <- forAllShrink(Either