Implement random_float and random_boolean
This commit is contained in:
parent
a0c648b33a
commit
50abe9765a
@ -7,7 +7,7 @@ mod output;
|
||||
mod random;
|
||||
mod r#type;
|
||||
|
||||
pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 11] = [
|
||||
pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 13] = [
|
||||
&assert::Assert,
|
||||
&assert::AssertEqual,
|
||||
&data_formats::FromJson,
|
||||
@ -17,6 +17,8 @@ pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 11] = [
|
||||
&fs::Append,
|
||||
&output::Output,
|
||||
&random::Random,
|
||||
&random::RandomBoolean,
|
||||
&random::RandomFloat,
|
||||
&random::RandomInteger,
|
||||
&r#type::Type,
|
||||
];
|
||||
|
@ -32,3 +32,31 @@ impl BuiltInFunction for RandomInteger {
|
||||
Ok(Value::Integer(random()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RandomFloat;
|
||||
|
||||
impl BuiltInFunction for RandomFloat {
|
||||
fn name(&self) -> &'static str {
|
||||
"random_float"
|
||||
}
|
||||
|
||||
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
|
||||
Error::expect_argument_amount(self, 0, arguments.len())?;
|
||||
|
||||
Ok(Value::Float(random()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RandomBoolean;
|
||||
|
||||
impl BuiltInFunction for RandomBoolean {
|
||||
fn name(&self) -> &'static str {
|
||||
"random_boolean"
|
||||
}
|
||||
|
||||
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
|
||||
Error::expect_argument_amount(self, 0, arguments.len())?;
|
||||
|
||||
Ok(Value::Boolean(random()))
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,7 @@ Simple Yield
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(expression
|
||||
(identifier))))))
|
||||
(identifier)))))
|
||||
|
||||
================================================================================
|
||||
Yield Chain
|
||||
@ -34,9 +33,6 @@ x -> (foo) -> (bar) -> (abc)
|
||||
(yield
|
||||
(expression
|
||||
(identifier))
|
||||
(expression
|
||||
(identifier))))
|
||||
(expression
|
||||
(identifier))))
|
||||
(expression
|
||||
(identifier))))))
|
||||
(identifier)))
|
||||
(identifier)))
|
||||
(identifier)))))
|
||||
|
Loading…
Reference in New Issue
Block a user