Today's AOC inspired idea for a utility function: ...
# advent-of-code
n
Today's AOC inspired idea for a utility function:
Copy code
fun String.popSuffix(suffix: String) = if (endsWith(suffix)) removeSuffix(suffix) else null
e
yeah, Rust's
fn strip_suffix() ->Option<&str>
returns
None
if it wasn't found, which is handy
I wish it would at least let us provide a fallback value, like
fun String.substringBefore(delimiter: Char, missingDelimiterValue: String): String
does
n
Right
might not be a bad idea to suggest, I even think popSuffix is a decent, distinct name for it