use crate::prelude::*;
use crate::registry::Registry;
use crate::tremor_const_fn;
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)]
pub fn load(registry: &mut Registry) {
registry.insert(tremor_const_fn! (range|range(_context, a, b) {
if let (Some(a), Some(b)) = (a.as_u64(), b.as_u64()) {
let range: Vec<Value> = (a..b).map(Value::from).collect();
Ok(Value::from(range))
} else if let (Some(a), Some(b)) = (a.as_i64(), b.as_i64()) {
let range: Vec<Value> = (a..b).map(Value::from).collect();
Ok(Value::from(range))
} else {
Err(FunctionError::BadType{mfa: this_mfa()})
}
}));
}
#[cfg(test)]
mod test {
use crate::registry::fun;
use crate::Value;
#[test]
fn range() {
let f = fun("range", "range");
let s = Value::from(0);
let e = Value::from(42);
let a: Vec<i32> = (0_i32..42_i32).collect();
assert_val!(f(&[&s, &e]), a);
}
}