swift-overture icon indicating copy to clipboard operation
swift-overture copied to clipboard

Potentially add `rethrows` to `over` and similar functions

Open stackotter opened this issue 3 years ago • 0 comments

Context

I'm trying to update some code that I think could really benefit from a functional style. Here's the current code:

let keyPaths: [WritableKeyPath<Config, String>] // ...

for keyPath in keyPaths {
  config[keyPath: keyPath] = try evaluator.evaluateExpression(config[keyPath: keyPath])
}

The problem

I've tried a few different approaches and none of them compile because evaluateExpression is a throwing function, and the overture functions I'm trying to use don't have rethrows. Here's my best attempt:

let evaluators = keyPaths.map { over($0, evaluator.evaluateExpression) }

for evaluateField in evaluators {
  config = try evaluateField(config)
}

Potential solutions

  1. I'm missing something and there's a better way to do this with a function that does have rethrows
  2. Add rethrows to all of the methods except where it doesn't make sense (I feel like over and co make sense to have rethrows)

stackotter avatar Mar 04 '22 07:03 stackotter