Files
ValueScript/valuescript_vm/src/array_higher_functions/array_every.rs
2023-07-07 16:08:28 +10:00

29 lines
795 B
Rust

use super::super::native_frame_function::NativeFrameFunction;
use super::super::vs_value::{Val, ValTrait};
use super::array_mapping_frame::{ArrayMappingFrame, ArrayMappingState};
pub static EVERY: NativeFrameFunction = NativeFrameFunction {
#[allow(clippy::box_default)]
make_frame: || Box::new(ArrayMappingFrame::new(Box::new(EveryState::default()))),
};
#[derive(Default, Clone)]
struct EveryState {}
impl ArrayMappingState for EveryState {
fn process(&mut self, _i: usize, _element: &Val, mapped: Val) -> Option<Val> {
match mapped.is_truthy() {
true => None,
false => Some(Val::Bool(false)),
}
}
fn finish(&mut self) -> Val {
Val::Bool(true)
}
fn clone_to_array_mapping_state(&self) -> Box<dyn ArrayMappingState> {
Box::new(self.clone())
}
}