but there would still need to have something along "https://google.com"..URL.init
I don't really like this pattern, honestly... Doesn't seems very swifty to me...
I prefer "https://google.com".asUrl.asRequest but yes, seems not that different from piping.
It'd be interesting to see how all this ideas interact with init that is not originally single-argument, but have default arguments, which includes URLRequest(url:).
I really like this idea on a conceptual level. For the most part I think the asSomething syntax, and the reversible initializer solves this problem pretty well, also with regards to access control. Although, ideally I would really like to also see something more in the lines of implicit conversion.
That could allow syntax like:
let urlString: String = "www.swift.org"
let url = urlString as URL
let request = url as URLRequest
or as a one-liner:
let request = ("www.swift.org" as URL) as URLRequest
I don't know if this type of language feature has been discussed a lot in the past, but this could also potentially solve some syntactical friction when dealing with numbers, etc.
I must say this idea did went through my mind yesterday but seeing it like you showed it is sexy. However "as" is more a downcast like in MyViewController as UIViewController or a bridgecast like in NSString as String. for an upcast, maybe we should use another keyword like "into"?
let request = ("www.swift.org" into URL) into URLRequest
but when you look at it , "into" become a pipe operator that allows for the righthand parameter to automatically add .init to URL.init
as michelf proposed:
let urlRequest = string |> URL.init |> URLRequest.init