I followed the code style used in `indexWhere` just above this method, where `from max 0` was used. If you think it is important, I can change the both methods to use `math.min` and `math.max` respectively.