Skip to content

Instantly share code, notes, and snippets.

@gpambrozio
Last active August 10, 2020 20:05
Show Gist options
  • Save gpambrozio/d3680d52b472d41b9c09a1226e33c529 to your computer and use it in GitHub Desktop.
Save gpambrozio/d3680d52b472d41b9c09a1226e33c529 to your computer and use it in GitHub Desktop.
Configurable
typealias ConfigurationClosure<T> = (inout T) throws -> Void
protocol Configurable {}
extension Configurable {
func configure(_ step: ConfigurationClosure<Self>) rethrows -> Self {
var mutableSelf = self
try step(&mutableSelf)
return mutableSelf
}
}
extension URL: Configurable {}
let a = URL(string: "whatever")?.configure {
$0.appendPathComponent("api")
}
func addingAPIPath(url: inout URL) {
url.appendingPathComponent("api")
}
let b = URL(string: "whatever")?
.configure(addingAPIPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment