scala implementation of binary search