pub fn single_or_tuple_any<T, F, M>(
    obj: PyObjectRef,
    predicate: &F,
    message: &M,
    vm: &VirtualMachine,
) -> PyResult<bool>
where
    T: TryFromObject,
    F: Fn(&T) -> PyResult<bool>,
    M: Fn(&PyObjectRef) -> String,
{
    match T::try_from_object(vm, obj.clone()) {
        Ok(single) => (predicate)(&single),
        Err(_) => {
            let tuple = PyTupleRef::try_from_object(vm, obj.clone())
                .map_err(|_| vm.new_type_error((message)(&obj)))?;
            for obj in tuple.borrow_value().iter() {
                if single_or_tuple_any(obj.clone(), predicate, message, vm)? {
                    return Ok(true);
                }
            }
            Ok(false)
        }
    }
}
/// Tests that the predicate is True on a single value, or if the value is a tuple a tuple, then
/// test that any of the values contained within the tuples satisfies the predicate. Type parameter
/// T specifies the type that is expected, if the input value is not of that type or a tuple of
/// values of that type, then a TypeError is raised.
Tests that the predicate is True on a single value, or if the value is a tuple a tuple, then
test that any of the values contained within the tuples satisfies the predicate. Type parameter
T specifies the type that is expected, if the input value is not of that type or a tuple of
values of that type, then a TypeError is raised.
Tests that the predicate is True on a single value or if the value is a tuple a tuple then test that any of the values contained within the tuples satisfies the predicate . Type parameter T specifies the type that is expected if the input value is not of that type or a tuple of values of that type then a TypeError is raised .
pub fn single_or_tuple_any<T, F, M>(
    obj: PyObjectRef,
    predicate: &F,
    message: &M,
    vm: &VirtualMachine,
) -> PyResult<bool>
where
    T: TryFromObject,
    F: Fn(&T) -> PyResult<bool>,
    M: Fn(&PyObjectRef) -> String,
{
    match T::try_from_object(vm, obj.clone()) {
        Ok(single) => (predicate)(&single),
        Err(_) => {
            let tuple = PyTupleRef::try_from_object(vm, obj.clone())
                .map_err(|_| vm.new_type_error((message)(&obj)))?;
            for obj in tuple.borrow_value().iter() {
                if single_or_tuple_any(obj.clone(), predicate, message, vm)? {
                    return Ok(true);
                }
            }
            Ok(false)
        }
    }
}
pub fn single_or_tuple_any < T , F , M > ( obj : PyObjectRef , predicate : & F , message : & M , vm : & VirtualMachine , ) -> PyResult < bool > where T : TryFromObject , F : Fn ( & T ) -> PyResult < bool > , M : Fn ( & PyObjectRef ) -> String , { match T :: try_from_object ( vm , obj . clone ( ) ) { Ok ( single ) => ( predicate ) ( & single ) , Err ( _ ) => { let tuple = PyTupleRef :: try_from_object ( vm , obj . clone ( ) ) . map_err ( | _ | vm . new_type_error ( ( message ) ( & obj ) ) ) ? ; for obj in tuple . borrow_value ( ) . iter ( ) { if single_or_tuple_any ( obj . clone ( ) , predicate , message , vm ) ? { return Ok ( true ) ; } } Ok ( false ) } } }
Tests that the predicate is True on a single value, or if the value is a tuple a tuple, then
test that any of the values contained within the tuples satisfies the predicate.
Tests that the predicate is True on a single value or if the value is a tuple a tuple then test that any of the values contained within the tuples satisfies the predicate .
obj
PyObjectRef
predicate
&F
message
&M
vm
&VirtualMachine