From 6fb0ff9177abad40d1a71607e79c7f638f86c874 Mon Sep 17 00:00:00 2001 From: Juan Abimael Santos Castillo <41840076+Abimael10@users.noreply.github.com> Date: Tue, 21 Oct 2025 12:45:58 -0400 Subject: [PATCH] chore(native): simplify Array::get method with functional approach (#13771) ## Issue The Array::get method used verbose nested Option handling with redundant returns, making the code longer and less Rust idiomatic. ## Solution Replaced the nested if let structure with a functional and_then approach that: - Eliminates redundant return keyword usage - Flattens Option handling for cleaner logic - Reduces code from 13 lines to 9 lines - Maintains identical functionality ## Result More idiomatic Rust code that's easier to read and maintain, with all tests passing. ## Summary by CodeRabbit * **Refactor** * Improved internal code structure with functional programming patterns for enhanced maintainability. No visible changes to end-user functionality. Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> --- packages/common/y-octo/core/src/doc/types/array.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/common/y-octo/core/src/doc/types/array.rs b/packages/common/y-octo/core/src/doc/types/array.rs index 6581895a20..3cf6c3aced 100644 --- a/packages/common/y-octo/core/src/doc/types/array.rs +++ b/packages/common/y-octo/core/src/doc/types/array.rs @@ -36,15 +36,13 @@ impl Array { pub fn get(&self, index: u64) -> Option { let (item, offset) = self.get_item_at(index)?; - if let Some(item) = item.get() { + item.get().and_then(|item| { // TODO: rewrite to content.read(&mut [Any]) - return match &item.content { - Content::Any(any) => return any.get(offset as usize).map(|any| Value::Any(any.clone())), + match &item.content { + Content::Any(any) => any.get(offset as usize).map(|any| Value::Any(any.clone())), _ => Some(Value::from(&item.content)), - }; - } - - None + } + }) } pub fn iter(&self) -> ArrayIter {