def _search(left, right, predicate):
    """Simple binary search that uses the ``predicate`` function to determine direction of search"""
    if right >= left:

        mid = left + (right - left) // 2

        res = predicate(mid)
        if res == 0:
            return mid

        elif res > 1:
            return _search(left, mid - 1, predicate)
        else:
            return _search(mid + 1, right, predicate)
    else:
        return -1