Git Product home page Git Product logo

Comments (4)

stephencelis avatar stephencelis commented on July 19, 2024 1

Oh nice! If that's the case and there are no conflicts, then I'm good with overloads!

from swift-overture.

stephencelis avatar stephencelis commented on July 19, 2024

This sounds reasonable to me! We'd def take a PR for this.

from swift-overture.

stephencelis avatar stephencelis commented on July 19, 2024

Hm, one consideration is composing throwing functions with non-throwing functions, which wouldn't be scalable with overloads.

pipe((A) throws -> B, (B) -> C)
// (A) throws -> C

So we'd probably want a way to "cast" non-throwing functions into throwing ones for the sake of composition. Something like:

pipe((A) throws -> B, throwing((B) -> C))
// (A) throws -> C

We typically compose with types, and throws complicates this. So one alternative direction to consider would be to introduce a Result or Either type with which we can convert between the throwing and non-throwing world.

unthrow((A) throws -> B) -> (A) -> Either<Error, B>
throwing((A) -> Either<Error, B>) -> (A) throws -> B

Not sure what direction we wanna go here...so maybe hold off on that PR after all, sorry!

from swift-overture.

vknabel avatar vknabel commented on July 19, 2024

I already played a bit around with this and defined a throwing chain3 in a playground.
As Swift allows non-optionals to be passed as optionals, it also allows non-throwing functions to be passed as a throwing function.

Below an example usage directly copied from my playground. The non-throwing chain3 can still be used without any problems. In this case they were defined on ([T], A) as I was experimenting with an arguments parser for CLIs.

func chain<Element, A, B, C>(
    _ f: @escaping ([Element]) throws -> ([Element], A),
    _ g: @escaping ([Element]) throws -> ([Element], B),
    _ h: @escaping ([Element]) throws -> ([Element], C)
) -> ([Element]) throws -> (A, B, C)

let (isVerbose, whoToGreet, _) = try with(["-v", "hi"], chain(
    flag("verbose", "v"), // does not throw
    argument(named: "Name"), // throws
    exhaust // throws
))

from swift-overture.

Related Issues (17)

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.