feat: progress iterators

This commit is contained in:
2026-09-13 18:23:25 +02:00
parent 88b981b50c
commit 50f23f7e48
3 changed files with 20 additions and 4 deletions
+13 -3
View File
@@ -11,21 +11,31 @@ enum DivisionError {
// TODO: Calculate `a` divided by `b` if `a` is evenly divisible by `b`.
// Otherwise, return a suitable error.
fn divide(a: i64, b: i64) -> Result<i64, DivisionError> {
todo!();
if b == 0 {
Err(DivisionError::DivideByZero)
} else if b == -1 && a == i64::MIN {
Err(DivisionError::IntegerOverflow)
} else if a % b == 0 {
Ok(a / b)
} else {
Err(DivisionError::NotDivisible)
}
}
// TODO: Add the correct return type and complete the function body.
// Desired output: `Ok([1, 11, 1426, 3])`
fn result_with_list() {
fn result_with_list() -> Result<Vec<i64>, DivisionError> {
let numbers = [27, 297, 38502, 81];
let division_results = numbers.into_iter().map(|n| divide(n, 27));
division_results.collect()
}
// TODO: Add the correct return type and complete the function body.
// Desired output: `[Ok(1), Ok(11), Ok(1426), Ok(3)]`
fn list_of_results() {
fn list_of_results() -> Vec<Result<i64, DivisionError>> {
let numbers = [27, 297, 38502, 81];
let division_results = numbers.into_iter().map(|n| divide(n, 27));
division_results.collect()
}
fn main() {