Struct arithmetic_eval::fns::Filter
source · pub struct Filter;
Expand description
Filter function that evaluates the provided function on each item of the tuple and retains
only elements for which the function returned true
.
Type
(using arithmetic-typing
notation)
(['T; N], ('T) -> Bool) -> ['T]
Examples
let program = "
xs = (1, -2, 3, -7, -0.3);
filter(xs, |x| x > -1) == (1, 3, -0.3)
";
let program = Untyped::<F32Grammar>::parse_statements(program)?;
let module = ExecutableModule::new("test_filter", &program)?;
let mut env = Environment::new();
env.insert_native_fn("filter", fns::Filter);
assert_eq!(module.with_env(&env)?.run()?, Value::Bool(true));
Trait Implementations§
source§impl<T: 'static + Clone> NativeFn<T> for Filter
impl<T: 'static + Clone> NativeFn<T> for Filter
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.
impl Copy for Filter
Auto Trait Implementations§
impl RefUnwindSafe for Filter
impl Send for Filter
impl Sync for Filter
impl Unpin for Filter
impl UnwindSafe for Filter
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