let mut journey = vec::new(); for dog in dogs_list { if !predismissal_criteria(dog) && !leave_out(dog) { journey.push(embark_from_the_beginning(dog)); } } let algorithm = |dog_journey: vec<_>| -> vec<_> { dog_journey.into_iter().filter(|&x| x != "withheld").collect() }; let final_list = algorithm(journey);