Rob Elliot
01/30/2023, 10:20 AMString
into a URI
.
For untrusted input ideally I want a function that forces the caller to handle the bad case - fun String.toUri(): Either<URISyntaxException, URI>
.
But that's a colossal pain when constructing from a string literal; I don't want "<http://www.example.com>".toUri()
to return an Either
, I want a URI
!
Of course you can provide two methods, one for untrusted input, one for trusted, but that immediately opens up the possibility of human error choosing the wrong one.
So I was wondering if a compiler plugin could actually infer that the function's arguments are known at compile time and actually call the function to prove that it returns a Right<URI>
, and in that case allow val uri: URI = "<http://www.example.com>".toUri()
to compile, and throw a compile error on val uri: URI = "not a uri".toUri()
.Rob Elliot
01/30/2023, 10:21 AMval uri: URI = runtimeInputString.toUri()
would not compile because the return type would be Either<URISyntaxException, URI>
.wasyl
01/30/2023, 10:30 AMRob Elliot
01/30/2023, 10:31 AMSam
01/30/2023, 10:43 AMRob Elliot
01/30/2023, 10:49 AM