(&self, args: &[Value], context: &Context)
| 30 | } |
| 31 | |
| 32 | fn invoke(&self, args: &[Value], context: &Context) -> Result<Value, DscError> { |
| 33 | debug!("{}", t!("functions.filter.invoked")); |
| 34 | |
| 35 | let array = args[0].as_array().unwrap(); |
| 36 | let lambda_id = args[1].as_str().unwrap(); |
| 37 | |
| 38 | let lambdas = get_lambda(context, lambda_id, "filter")?; |
| 39 | let lambda = lambdas.get(lambda_id).unwrap(); |
| 40 | |
| 41 | let result_array = apply_lambda_to_array(array, lambda, context, |result, element| { |
| 42 | let Some(include) = result.as_bool() else { |
| 43 | return Err(DscError::Parser(t!("functions.filter.lambdaMustReturnBool").to_string())); |
| 44 | }; |
| 45 | if include { |
| 46 | Ok(Some(element.clone())) |
| 47 | } else { |
| 48 | Ok(None) |
| 49 | } |
| 50 | })?; |
| 51 | |
| 52 | Ok(Value::Array(result_array)) |
| 53 | } |
| 54 | } |
nothing calls this directly
no test coverage detected