Skip to content

Instantly share code, notes, and snippets.

@FranDepascuali
Created August 23, 2016 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranDepascuali/3b8b3152b06ba8562e83b84b45f4682c to your computer and use it in GitHub Desktop.
Save FranDepascuali/3b8b3152b06ba8562e83b84b45f4682c to your computer and use it in GitHub Desktop.
protocol Downloader {
func fetch(from url: SecureURLType)
}
protocol SecureURLType {
init?(from url: URL, validator: URL -> Bool)
}
private let DefaultValidator: URL -> Bool = { _ in true }
struct SecureURL: SecureURLType {
private let _url: URL
init?(from url: URL, validator: URL -> Bool = DefaultValidator) {
guard validator(url) else {
return nil
}
_url = url
}
}
let url = NSURL(string: "https://www.google.com.ar/")!
guard let secureURL = SecureURL(from: url) else {
print("Cannot make a request to an internal ip!")
}
@alanhala
Copy link

Che que es NSURL? No es un nombre claro

@alanhala
Copy link

print("Cannot make a request to an internal ip!") Hardcoded string

@gnardini
Copy link

let DefaultValidator: URL -> Bool = { _ in true }
Posta, te parece que _ in true es claro? Vos que tanto queres que todo sea claro. Y este encima es un caso tonto. No es intuitivo, simplemente es una 'convencion' de funcional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment