Giter Club home page Giter Club logo

curry's Introduction

Carthage compatible

Curry

Swift implementations for function currying.

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

Installation

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"),
]
github "thoughtbot/Curry"

Then run carthage update.

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

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

thoughtbot

This repo 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. We are available for hire.

curry's People

Contributors

gfontenot avatar github-actions[bot] avatar ikesyo avatar johnnysay avatar jshier avatar mbrandonw avatar mokagio avatar nickygerritsen avatar paulyoung avatar pyroh avatar sharplet avatar stevehanson avatar tkohout avatar tonyd256 avatar toomey8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

curry's Issues

Swift 4 support

Hi
Is the current version of curry support Swift 4 ?
I've tried updating my project today and keep having this error: Ambiguous use of 'curry'.

Thanks

Curry v4.0.0 pod install issue

The latest release by curry is unable to be installed via PodFile.

My PodFile contains pod 'Curry', '4.0.0'

When I execute pod install I get the following error shown in the image.

screen shot 2017-12-28 at 6 14 21 pm

Warnings: "extraneous '_' in parameter

Howdy! I'm posting this in case the author(s) are unaware that with the Swift 2.x toolchains, there are currently warnings on each function decl regarding the first parameter label.
Example:

~proj/Carthage/Checkouts/Curry/Source/Curry.swift:1:25: warning: extraneous '_' in parameter: 'function' has no keyword argument name
~proj/Carthage/Checkouts/Curry/Source/Curry.swift:5:28: warning: extraneous '_' in parameter: 'function' has no keyword argument name
~proj/Carthage/Checkouts/Curry/Source/Curry.swift:9:31: warning: extraneous '_' in parameter: 'function' has no keyword argument name
~proj/Carthage/Checkouts/Curry/Source/Curry.swift:13:34: warning: extraneous '_' in parameter: 'function' has no keyword argument name

This was (rightfully) changed for Swift 3 it appears, right here, to avoid requiring those argument labels going forward. I realize it may not be of interest or urgency to correct this issue since everything still technically works on Swift 2.x, however I figured I would post this anyway for awareness even in case another user was confused by these warnings. This being said though, it may be pretty easy to modify the generation script for these funcs to declare 2 different versions of them with swift version compiler checks (#if swift(...)). I believe this would not result in any extraneous/duplicate overloads being actually compiled and put into the binary, so only the size of Curry.swift suffers. I'm interested if anyone has thoughts on this, or if it would be worth doing/accepted to make this change and PR it.

Thanks for reading! Argo and Curry are great. Cheers.

Does it make sense to curry in Swift?

It is actually not an issue in your code, but I would like to hear your thoughts. I hope you don't mind I open the issue.

I recently tried to write some functions for partial application of parameters to the given functions. Pretty similar to currying, but if the original function had 4 parameters, I could apply 3 and have a function that expects only one. Fewer ()s, same concept.

Played with the code a little bit and gave it up. Not because I had a problem with that, but because I thought it might be harmful.
That brings me to the original question, does it make sense to write this kind of functional goodies in Swift?

My primary reason to give it up was ARC.
With currying you retain strong references to the params in the closure. If the curried function is not consumed immediately, but retained for longer time (which often makes sense), you risk to create strong reference loops and eventually memory leaks.

To me, although Swift comes with some functional support, taking int seriously and diving deep in the functional programming seems not really an option.
What do you think. Do you take any special care, what functions and parameters you curry? Or do you ignore the problem and assume it will not happen? I am looking forward to your comments.

Xcode 11 Beta 4 (Swift 5.1 run time support)

Hi All,

I'm using latest version Curry (v4.0.2) using Carthage. Having issues while building on Xcode 11 Beta 4 (11M374r). Had following issue while building
Screenshot 2019-08-24 at 9 45 12 pm

Any help here is really helpful

"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.

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.

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)

20 parameter limit

Hi ,

I'm using version Curry (v4.0.2) with CocoaPods。

Xcode version 11.5

a issues that curry parameters are limited to 20. What should I do if there are more than 20 parameters

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

Make Curry release for new syntax?

Anything stopping y'all from making a new release with the preferred Swift 2.2 syntax?

Wanted to update Argo to get rid of some warnings in my projects.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.