4 ms·
Isn't this solvable just by using types and instances rather than just calling top level/static functions? If you have a "replace" function off of String and us
by vips7L 3y ago
Isn't this solvable just by using types and instances rather than just calling top level/static functions? If you have a "replace" function off of String and use a Pattern type instead of a raw string, the compiler will enforce the correct type and ordering.
val p = Pattern("https://[^/]*")
val in = "https://google.com/some/path"
val path = in.replace(p, "") // /some/path
In fact this specific example is solved just by having a dedicated type, for example URI:
val path = URI("https://google/com/some/path").path; // /some/path
This feels like to me an answer in search of a problem.