Here is an example function with the pattern I am referring to:
fn check_sub_listiness<T: PartialEq>(big_list: &[T], small_list: &[T]) -> bool {
for poss_sublist in big_list.windows(small_list.len()) {
if poss_sublist == small_list {
return true;
}
}
false
}
This code takes a big list and a small list and returns whether the small list is a sublist of the big list. I wrote it as part of an Exercism exercise I was doing. I find myself using this pattern alot, where I loop through some options, check for a condition, and return true if I find it or false if I make it to the end of the loop without finding what I was looking for. Is there a name for this? More importantly, is there a better more semantic way to write it (in Rust or any other language).