pub struct Fold;Expand description
Reduce (aka fold) function that reduces the provided tuple to a single value.
§Type
(using arithmetic-typing notation)
(['T], 'Acc, ('Acc, 'T) -> 'Acc) -> 'Acc§Examples
let program = "
xs = (1, -2, 3, -7);
fold(xs, 1, |acc, x| acc * x) == 42
";
let program = Untyped::<F32Grammar>::parse_statements(program)?;
let module = ExecutableModule::new("test_fold", &program)?;
let mut env = Environment::new();
env.insert_native_fn("fold", fns::Fold);
assert_eq!(module.with_env(&env)?.run()?, Value::Bool(true));Trait Implementations§
impl Copy for Fold
Source§impl<T: 'static + Clone> NativeFn<T> for Fold
impl<T: 'static + Clone> NativeFn<T> for Fold
Source§fn evaluate(
&self,
args: Vec<SpannedValue<T>>,
ctx: &mut CallContext<'_, T>,
) -> EvalResult<T>
fn evaluate( &self, args: Vec<SpannedValue<T>>, ctx: &mut CallContext<'_, T>, ) -> EvalResult<T>
Executes the function on the specified arguments.
Auto Trait Implementations§
impl Freeze for Fold
impl RefUnwindSafe for Fold
impl Send for Fold
impl Sync for Fold
impl Unpin for Fold
impl UnsafeUnpin for Fold
impl UnwindSafe for Fold
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more