Comments (4)
Oh nice! If that's the case and there are no conflicts, then I'm good with overloads!
from swift-overture.
This sounds reasonable to me! We'd def take a PR for this.
from swift-overture.
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.
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)
- Consider a more 'swifty' API HOT 4
- zip(with:) are not public ? HOT 1
- iOS target for Carthage HOT 5
- Ambiguous use of `with` HOT 2
- Redefine `set` without `over` HOT 1
- Add Info.plist HOT 1
- Currying higher order functions obscures type. HOT 2
- Compile times of with, concat & mut functions in swift4 are very high!! HOT 2
- Add zip to Result HOT 1
- getting EXC_BAD_ACCESS while calling overture methods in static vars HOT 3
- Adding the operators counterpart HOT 5
- `with` is different from how it's portrayed in readme HOT 3
- Compilation failure using mut on a navigation controller HOT 1
- Is there a better way to style UINavigation's bar appearance?
- Add @discardableResult to update() HOT 4
- Potentially add `rethrows` to `over` and similar functions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-overture.