monadic extension of binary search.