Davio
06/27/2022, 8:37 AMtoDoubleOrNull() (similar functions exist for other numeric types). This extension function is defined on String instead of String? Would it make sense to define this function on String? instead so a null-valued String just returns null?
I noticed that toBoolean() is defined on String? as well.Rob Elliot
06/27/2022, 8:49 AMDavio
06/27/2022, 8:53 AMRuckus
06/27/2022, 3:12 PMtoBoolean() because a null input is mapped to a different output (false in this case). If, however, a null input is always a null output, there's no reason to accept null inputs as the language already has a built in way to handle that in the general case (i.e. ?.).ephemient
06/28/2022, 6:08 AM.toBoolean() isn't a great example anyway; its behavior is a carry-over from Java's Boolean.parseBoolean, but unless you need to be precisely compatible with that, I would recommend .toBooleanStrict() or .toBooleanStrictOrNull() instead