From b08a727fe3281dd3593093e1f2e7e77f4496acd6 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Fri, 5 Dec 2025 20:36:28 -0500 Subject: [PATCH] remove some unwrap_unchecked --- src/math_app.rs | 9 ++------- src/misc.rs | 6 ++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/math_app.rs b/src/math_app.rs index 1323ad8..74e6bd2 100644 --- a/src/math_app.rs +++ b/src/math_app.rs @@ -489,13 +489,8 @@ impl App for MathApp { .iter() .map(|(_, func)| func.get_test_result()) .enumerate() - .filter(|(_, error)| error.is_some()) - .map(|(i, error)| { - // use unwrap_unchecked as None Errors are already filtered out - unsafe { - format!("(Function #{}) {}\n", i, error.as_ref().unwrap_unchecked()) - } - }) + .filter_map(|(i, error)| error.as_ref().map(|x| (i, x))) + .map(|(i, error)| format!("(Function #{}) {}\n", i, error)) .join(""); if !errors_formatted.is_empty() { diff --git a/src/misc.rs b/src/misc.rs index 995bf7d..cd6df10 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,5 +1,5 @@ -use base64::Engine; use base64::engine::general_purpose; +use base64::Engine; use egui_plot::{Line, PlotPoint, PlotPoints, Points}; use emath::Pos2; use itertools::Itertools; @@ -91,9 +91,7 @@ pub fn newtons_method_helper( .filter(|(prev, curr)| prev.y.is_finite() && curr.y.is_finite()) .filter(|(prev, curr)| prev.y.signum() != curr.y.signum()) .map(|(start, _)| start.x) - .map(|x| newtons_method(f, f_1, x, range, threshold)) - .filter(|x| x.is_some()) - .map(|x| unsafe { x.unwrap_unchecked() }) + .filter_map(|x| newtons_method(f, f_1, x, range, threshold)) .collect() }