Skip to content

Commit ce988d5

Browse files
committed
Use ControlFlow instead of Result.
1 parent 2d94e82 commit ce988d5

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

jaq-interpret/src/filter.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::results::{fold, recurse, then, Fold, Results};
33
use crate::val::{Val, ValR, ValRs};
44
use crate::{rc_lazy_list, Bind, Ctx, Error};
55
use alloc::{boxed::Box, string::String, vec::Vec};
6+
use core::ops::ControlFlow;
67
use dyn_clone::DynClone;
78
use jaq_syn::filter::FoldType;
89
use jaq_syn::{MathOp, OrdOp};
@@ -342,9 +343,9 @@ impl<'a> FilterT<'a> for Ref<'a> {
342343
Vec::from([Box::new(run_cvs(def, cvs)) as Results<_, _>]),
343344
move |r| match r {
344345
Err(Error::TailCall(TailCall(id, vars, v))) if id == call.id => {
345-
Err(def.run((Ctx { inputs, vars }, v)))
346+
ControlFlow::Continue(def.run((Ctx { inputs, vars }, v)))
346347
}
347-
Ok(_) | Err(_) => Ok(r),
348+
Ok(_) | Err(_) => ControlFlow::Break(r),
348349
},
349350
)),
350351
CallTyp::Throw => Box::new(cvs.map(move |cv| {

jaq-interpret/src/stack.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::vec::Vec;
2+
use core::ops::ControlFlow;
23

34
pub struct Stack<I, F>(Vec<I>, F);
45

@@ -8,9 +9,9 @@ impl<I, F> Stack<I, F> {
89
}
910
}
1011

11-
/// If `F` returns `Ok(x)`, then `x` is returned
12-
/// If `F` returns `Err(iter)`, then the iterator is pushed onto the stack
13-
impl<I: Iterator, F: Fn(I::Item) -> Result<I::Item, I>> Iterator for Stack<I, F> {
12+
/// If `F` returns `Break(x)`, then `x` is returned
13+
/// If `F` returns `Continue(iter)`, then the iterator is pushed onto the stack
14+
impl<I: Iterator, F: Fn(I::Item) -> ControlFlow<I::Item, I>> Iterator for Stack<I, F> {
1415
type Item = I::Item;
1516

1617
fn next(&mut self) -> Option<Self::Item> {
@@ -24,8 +25,8 @@ impl<I: Iterator, F: Fn(I::Item) -> Result<I::Item, I>> Iterator for Stack<I, F>
2425
self.0.push(top);
2526
}
2627
match self.1(next) {
27-
Ok(next) => return Some(next),
28-
Err(iter) => self.0.push(iter),
28+
ControlFlow::Break(next) => return Some(next),
29+
ControlFlow::Continue(iter) => self.0.push(iter),
2930
}
3031
}
3132
}

0 commit comments

Comments
 (0)