Swift implementations for function currying

Related tags

Utility Curry
Overview

Carthage compatible

Curry

Swift implementations for function currying.

For more info on function currying in Swift, please refer to this blog post

Version Compatibility

Note that we're aggressive about pushing master forward along with new versions of Swift. Therefore, we highly recommend against pointing at master, and instead using one of the releases we've provided.

Installation

Swift Package Manager

Add this as a package dependency in Xcode:

https://github.com/thoughtbot/Curry

Or add it as a dependency in your Package.swift file:

dependencies: [
  .package(url: "https://github.com/thoughtbot/Curry", from: "5.0.0"),
]

Carthage

github "thoughtbot/Curry"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

CocoaPods

Add the following to your Podfile:

pod 'Curry'

You will also need to make sure you're opting into using frameworks:

use_frameworks!

Then run pod install with CocoaPods 0.36 or newer.

Contributing

See the CONTRIBUTING document. Thank you, contributors!

License

Curry is Copyright (c) 2015 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

thoughtbot

Curry is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects or look at our product case studies and hire us to help build your iOS app. We also have a collection of resources for learning iOS development at Upcase.

Comments
  • Use universal build settings

    Use universal build settings

    Curry is a really simple framework, and it sucks to have to manage multiple targets and schemes to properly distribute it. Instead, we can use some clever xcconfigs to let a single framework target (and a single scheme) build multiple frameworks for us.

    opened by gfontenot 11
  • Add tvOS target

    Add tvOS target

    I'm not sure whether you already want to add this before the watchOS SDK gets a GM or stable release, but nevertheless you can then probably use it later without changing much. I needed it anyway to test an SDK I am creating on tvOS so I might as well create a PR for it :).

    opened by nickygerritsen 11
  • A limit for Swift compiler?

    A limit for Swift compiler?

    I am using currying for options in Commandant library.

    Following code will not compile and aborted with type inference error.

    struct Options: OptionsProtocol {
        fileprivate let filePath: String
        fileprivate let debug: Bool
        fileprivate let outputFilePath: String
        fileprivate let transform: String
        fileprivate let list: Bool
        fileprivate let templateFilePath: String
        fileprivate let commentsHeaderPath: String
        fileprivate let moduleFilePath: String
        
        public static func create() -> (String) -> (Bool) -> (String) -> (String) -> (Bool) -> (String) -> (String) -> (String) -> Self {
            return  { a in
                    { b in
                    { c in
                    { d in
                    { e in
                    { f in
                    { g in
                    { h in
                        Options.init(filePath: a, debug: b, outputFilePath: c, transform: d, list: e, templateFilePath: f, commentsHeaderPath: g, moduleFilePath: h)
                }}}}}}}}
        }
        
        public static func evaluate(_ m: CommandMode) -> Result<Self, CommandantError<Swift.Error>> {
            return curry(Self.init)
                <*> m <| Option(key: "filePath", defaultValue: "", usage: "The path to the file in 'generate' action.")
                <*> m <| Switch(flag: "d", key: "debug", usage: "DEBUG")
                <*> m <| Option(key: "outputFilePath", defaultValue: "", usage: "Use with flag --filePath. It will output to this file")
                <*> m <| Option(key: "transform", defaultValue: "", usage: "Transform with name or shortcut.")
                <*> m <| Switch(flag: "l", key: "list", usage: "List available transforms")
                <*> m <| Option(key: "templateFilePath", defaultValue: "", usage: "Template file that should be used in some transforms")
                <*> m <| Option(key: "commentsHeaderPath", defaultValue: "", usage: "Comments header file that will be included at top")
                <*> m <| Option(key: "moduleFilePath", defaultValue: "", usage: "Module file that will be included at top after comments if presented")
        }
    }
    

    UPD: Error while compiling ( with Internal error in Source code editor when it prays to file a bug. )

    <unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
    <unknown>:0: note: Type variable id overflow
    
    opened by lolgear 10
  • Fix Swift 4 ambiguity

    Fix Swift 4 ambiguity

    Latest Xcode 9 beta 3 shows ambiguous use of curry when the swift 4 version flag is set for the project.

    screen shot 2017-07-18 at 9 34 16 pm

    This is likely related to changes in compiler implementation in swift 4 - see more here: https://github.com/Swinject/SwinjectAutoregistration/issues/29

    The solution is to disambiguate by adding parentheses to functions with more than one parameter. As far as I tested this, it should be backward compatible with earlier versions of swift.

    I would wait before merging this to see whether it is a bug of compiler in the beta or a real change.

    opened by tkohout 10
  • "Expression too complex" errors happening too often/quickly

    With the new syntax/arrity of curry, we seem to be hitting these complexity errors shockingly fast. Sometimes as quickly as 5 properties. This sucks. We should either:

    1. Drop the number of curry functions to 26, since for some reason that nearly doubles the number of applications we can perform
    2. Suggest that users always save the curried method off to an intermediate variable, since that nearly triples the number of applications
    3. All of the above.
    opened by gfontenot 10
  • MOAR CURRY!!

    MOAR CURRY!!

    The generator has been updated to Swift 2.0 and also has been rewritten to generate endless curry functions by concatenating the alphabet as it goes, ie ...Y, Z, AA, AB, etc.

    The biggest change is that it was rewritten to use the other curry syntax, (a: A)(b: B) instead of A -> B. This is easier on the compiler and we can far extend the limit. It also compiles instantly.

    The limit of generic parameters was found to be 64, which I think is interestingly a power of 2. I wonder if that number is either hard coded in Swift or if Swift internally uses a small amount of bits for this. ANYWAYS, I think if you need more than a 64 parameter curry function then you're probably doing it wrong.

    opened by tonyd256 10
  • Curry.swift vs Curry.framework

    Curry.swift vs Curry.framework

    Argo recently started including Runes.swift instead of Runes.framework, which is awesome for people using Argo since it's one less framework to deal with unless they're using Runes for other purposes.

    Am I correct in thinking the same thing could be done for Curry, or is there something special Argo does with only including operator definitions for Runes?

    If a framework included Curry.swift as a private dependency, a consumer of that framework should also be able to add Curry.framework (or Curry.swift, I suppose) without any conflicts, correct?

    I'd love to leverage Curry as a private dependency in this way to alleviate the burden of dealing with yet another framework.

    opened by paulyoung 7
  • Allow throwing functions to be curried

    Allow throwing functions to be curried

    Is there any reason why this hasn't been done? Seems like it would just require adding throws to the generated curry functions.

    Usage would be like:

    func foo(a: Int, b: Int) throws -> Int { ... }
    
    let curried = curry(foo)
    // curried: (a: Int) -> (b: Int) throws -> Int
    
    try curried(1)(2)
    
    
    opened by elliottwilliams 6
  • Full bitcode support

    Full bitcode support

    Added full bitcode support as described in Carthage/Carthage#535.

    The user-defined setting added allows the framework to be built with bitcode, otherwise the linker fails with a nasty error message:

    ld: bitcode bundle could not be generated because '/.../yourapp-ios/Carthage/Build/iOS/Curry.framework/Curry' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build for architecture arm64
    
    opened by renatorodrigues 6
  • Add Swift generator script for the source file

    Add Swift generator script for the source file

    It's written in Swift and slightly functional, which seems appropriate ☺️

    It might be a bit silly to add this at this point, since the framework is there already, but hey it might come in handy later on ¯_(ツ)_/¯

    opened by mokagio 6
  • SwiftPM support will be outdated on Swift 5

    SwiftPM support will be outdated on Swift 5

    This project now has a Package.swift file whose swift-tools-version is 3.0, but Swift 5 drops support for Swift 3 language mode, so this package cannot be used from SwiftPM on Swift 5.

    Could you update the manifest or add additional one of [email protected] (or [email protected]) and cut a new release?

    Ref: https://github.com/Carthage/Carthage/issues/2694

    opened by ikesyo 4
Releases(v5.0.0)
  • v5.0.0(May 22, 2020)

    This release doesn't have any source changes, but does add tooling support for Swift 5 and Swift 5.2 so that should probably count for something.

    Source code(tar.gz)
    Source code(zip)
  • v4.0.2(Mar 12, 2019)

    This is a small compatibility release for future versions of the Swift Package Manager. We now (theoretically) support building with Swift 3, 4, and 5 simultaneously.

    Source code(tar.gz)
    Source code(zip)
  • v4.0.1(Apr 15, 2018)

    This is a tiny release that only serves to silence warnings in the Xcode project when opening it with Xcode 9.3. If you're not using the Xcode project as a sub-project this release will mean nothing to you. If you are using the Xcode project as a sub-project this release will mean everything to you.

    Source code(tar.gz)
    Source code(zip)
  • v4.0.0(Dec 13, 2017)

  • v3.0.0(Oct 12, 2016)

  • v2.3.3(Jul 22, 2016)

  • v2.3.2(Jul 8, 2016)

  • v2.3.1(Jun 17, 2016)

    As a part of 2.3, we (I) totally forgot that Swift 3.0 no longer ignores the external label on the initial argument. That's my bad. 2.3.1 fixes that by re-ignoring that external label so that we get back to API compatibility.

    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(Jun 14, 2016)

    This release introduces Swift 3.0 support. The only change is that the types in the curried return value are wrapped in parens as required by Swift 3.0. This change is backwards compatible with Swift 2.X.

    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Apr 7, 2016)

    That thing where I said 2.1 included versions of curry for functions out to 21 arguments? I 100% lied to you and I apologize. 2.1 only included implementations for up to 19 arguments. Unacceptable. @mbrandonw noticed the mistake and fixed our code generator so that this release includes curry for functions out to 21 arguments.

    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Apr 6, 2016)

  • v2.0.0(Mar 5, 2016)

    Curry.framework 2.0 reverts the syntax used for curry back to the explicit closure syntax, making it compatible with the upcoming changes to Swift.

    • [CHANGED]: Curry now uses an explicit currying syntax for the curry function
    • [CHANGED]: Due to compiler limitations, the number of curry implementations has been dropped back to 18 arguments. This is a breaking change.
    • [NEW]: Curry.framework now fully supports building with Swift Package Manager :tada:
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Oct 30, 2015)

  • v1.3.0(Oct 11, 2015)

    • [NEW]: Curry functions have been rewritten to have no external labels. This helps prevent issues with partial application where the type didn't match up because the compiler was expecting a named parameter (Thanks @tonyd256!)
    • [NEW]: Curry functions are now implemented out to 64 (!!) parameters, which is insane and if you need more than that you should probably seek serious psychological treatment. (Thanks @tonyd256!)
    • [NEW]: Curry functions are generated by a swift script, because typing all of these out by hand is for suckers, and I definitely didn't do that when I originally wrote this lib (Thanks @mokagio!)
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Sep 11, 2015)

  • v1.1.1(Sep 4, 2015)

  • v1.1.0(Aug 10, 2015)

  • v1.0.0(Jul 9, 2015)

Owner
thoughtbot, inc.
We work with organizations of all sizes to design, develop, and grow their web and mobile products.
thoughtbot, inc.
Sugar is a sweetener for your Cocoa implementations.

Sugar is a sweetener for your Cocoa implementations. Table of Contents iOS Application Screen Simulator Keyboard Observer iOS Extensions UIView

HyperRedink 1.1k Dec 29, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Jiwon 0 Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Alessio Nossa 12 Dec 29, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022
Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Gordan Glavaš 7 Nov 24, 2022
Swift-compute-runtime - Swift runtime for Fastly Compute@Edge

swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea

Andrew Barba 57 Dec 24, 2022
Swift-HorizontalPickerView - Customizable horizontal picker view component written in Swift for UIKit/iOS

Horizontal Picker View Customizable horizontal picker view component written in

Afraz Siddiqui 8 Aug 1, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022
Sovran-Swift: Small, efficient, easy. State Management for Swift

Sovran-Swift: Small, efficient, easy. State Management for Swift

Segment 5 Jan 3, 2023
A Swift app, named 'iPose', for iPhone's pose measurement based on Swift.

iPhone's pose measurement based on Swift. This is a Swift app, named 'iPose', for iPhone's pose measurement based on Swift. This is a side project to

Ghasem Abdi 3 Jul 26, 2022
Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Elegant Chaos 4 Jul 20, 2022
Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway

Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway deployed on Graviton arm64 build swift:5.6.2-amazonlinux2-docker image

Furqan 2 Aug 16, 2022
A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

Brent Mifsud 33 Oct 3, 2022
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023