Preparation for sharing

- rustfmt
- clippy
- comments
- README
This commit is contained in:
2023-05-25 19:14:24 +01:00
parent e99ade92ba
commit bc2714aad8
144 changed files with 3734 additions and 3243 deletions

View File

@@ -1,20 +1,20 @@
use std::iter;
/// Iterate over a sequence with the first element the function returns
/// Some() for updated, but only if there is such an element.
pub fn replace_first<
T: Clone,
F: FnMut(&T) -> Option<T>
>(
slice: &[T], mut f: F
/// Iterate over a sequence with the first element updated for which the
/// function returns Some(), but only if there is such an element.
pub fn replace_first<T: Clone, F: FnMut(&T) -> Option<T>>(
slice: &[T],
mut f: F,
) -> Option<impl Iterator<Item = T> + '_> {
for i in 0..slice.len() {
if let Some(new) = f(&slice[i]) {
let subbed_iter = slice[0..i].iter().cloned()
let subbed_iter = slice[0..i]
.iter()
.cloned()
.chain(iter::once(new))
.chain(slice[i+1..].iter().cloned());
return Some(subbed_iter)
.chain(slice[i + 1..].iter().cloned());
return Some(subbed_iter);
}
}
None
}
}