MCPcopy Create free account
hub / github.com/PowerShell/DSC / invoke

Method invoke

lib/dsc-lib/src/functions/filter.rs:32–53  ·  view source on GitHub ↗
(&self, args: &[Value], context: &Context)

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 5

get_lambdaFunction · 0.85
apply_lambda_to_arrayFunction · 0.85
ArrayClass · 0.85
as_strMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected