Peter Ertl
03/24/2021, 2:09 PMRuckus
03/24/2021, 2:18 PMint
instead of char
is so it can return a -1
if you've reached the EOI.Peter Ertl
03/24/2021, 2:18 PMPeter Ertl
03/24/2021, 2:19 PMPeter Ertl
03/24/2021, 2:19 PMRuckus
03/24/2021, 2:19 PMPeter Ertl
03/24/2021, 2:20 PMPeter Ertl
03/24/2021, 2:20 PMPeter Ertl
03/24/2021, 2:20 PMinput.read().takeIf { it != -1 }?.toChar()
Ruckus
03/24/2021, 2:21 PMRuckus
03/24/2021, 2:22 PMInt
and the Char
. Whether that matters is entirely dependent on your use case. In general it's most likely fine, but worth keeping in mind if it's in a hot loop and you see any performance issues.Peter Ertl
03/24/2021, 2:22 PMPeter Ertl
03/24/2021, 2:23 PMRuckus
03/24/2021, 2:27 PMOption
or Result
type, but unfortunately those aren't free on the JVM.Peter Ertl
03/24/2021, 2:28 PMPeter Ertl
03/24/2021, 2:28 PMPeter Ertl
03/24/2021, 2:29 PMRuckus
03/24/2021, 2:30 PM-1
as a sentinel is such a well established standard in Java at this point I doubt many will see the need (or want) to change it. I could be wrong though...Ruckus
03/24/2021, 2:32 PMindexOf
uses it.Peter Ertl
03/24/2021, 2:32 PMRuckus
03/24/2021, 2:33 PMephemient
03/24/2021, 4:07 PMindexOf()
uses -1 as a sentinel. that will stay unless there's an inexpensive alternative