From 3760748fddd3b793c79c370398a9d4a3fc5afc04 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 20 Sep 2022 19:49:47 +0200 Subject: Refactor error handling --- src/eval/array.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/eval/array.rs') diff --git a/src/eval/array.rs b/src/eval/array.rs index 6d558393..b77ce93c 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -4,7 +4,7 @@ use std::ops::{Add, AddAssign}; use std::sync::Arc; use super::{ops, Args, Func, Value, Vm}; -use crate::diag::{At, StrResult, TypResult}; +use crate::diag::{At, SourceResult, StrResult}; use crate::syntax::Spanned; use crate::util::ArcExt; @@ -124,7 +124,7 @@ impl Array { } /// Return the first matching element. - pub fn find(&self, vm: &mut Vm, f: Spanned) -> TypResult> { + pub fn find(&self, vm: &mut Vm, f: Spanned) -> SourceResult> { for item in self.iter() { let args = Args::new(f.span, [item.clone()]); if f.v.call(vm, args)?.cast::().at(f.span)? { @@ -136,7 +136,7 @@ impl Array { } /// Return the index of the first matching element. - pub fn position(&self, vm: &mut Vm, f: Spanned) -> TypResult> { + pub fn position(&self, vm: &mut Vm, f: Spanned) -> SourceResult> { for (i, item) in self.iter().enumerate() { let args = Args::new(f.span, [item.clone()]); if f.v.call(vm, args)?.cast::().at(f.span)? { @@ -149,7 +149,7 @@ impl Array { /// Return a new array with only those elements for which the function /// returns true. - pub fn filter(&self, vm: &mut Vm, f: Spanned) -> TypResult { + pub fn filter(&self, vm: &mut Vm, f: Spanned) -> SourceResult { let mut kept = vec![]; for item in self.iter() { let args = Args::new(f.span, [item.clone()]); @@ -161,10 +161,9 @@ impl Array { } /// Transform each item in the array with a function. - pub fn map(&self, vm: &mut Vm, f: Spanned) -> TypResult { + pub fn map(&self, vm: &mut Vm, f: Spanned) -> SourceResult { let enumerate = f.v.argc() == Some(2); - Ok(self - .iter() + self.iter() .enumerate() .map(|(i, item)| { let mut args = Args::new(f.span, []); @@ -174,11 +173,11 @@ impl Array { args.push(f.span, item.clone()); f.v.call(vm, args) }) - .collect::>()?) + .collect() } /// Whether any element matches. - pub fn any(&self, vm: &mut Vm, f: Spanned) -> TypResult { + pub fn any(&self, vm: &mut Vm, f: Spanned) -> SourceResult { for item in self.iter() { let args = Args::new(f.span, [item.clone()]); if f.v.call(vm, args)?.cast::().at(f.span)? { @@ -190,7 +189,7 @@ impl Array { } /// Whether all elements match. - pub fn all(&self, vm: &mut Vm, f: Spanned) -> TypResult { + pub fn all(&self, vm: &mut Vm, f: Spanned) -> SourceResult { for item in self.iter() { let args = Args::new(f.span, [item.clone()]); if !f.v.call(vm, args)?.cast::().at(f.span)? { -- cgit v1.2.3