Retrieves a lambda from the context and validates it has 1 or 2 parameters. # Arguments `context` - The context containing the lambda registry `lambda_id` - The lambda ID string (e.g., `__lambda_ `) `func_name` - The name of the calling function (for error messages) # Returns A reference to the borrowed lambdas HashMap. The caller must use the returned `Ref` to access the lambda to keep t
(
context: &'a Context,
lambda_id: &str,
func_name: &str,
)
| 31 | /// |
| 32 | /// Returns an error if the lambda is not found or has invalid parameter count. |
| 33 | pub fn get_lambda<'a>( |
| 34 | context: &'a Context, |
| 35 | lambda_id: &str, |
| 36 | func_name: &str, |
| 37 | ) -> Result<Ref<'a, std::collections::HashMap<String, Lambda>>, DscError> { |
| 38 | let lambdas = context.lambdas.borrow(); |
| 39 | |
| 40 | if !lambdas.contains_key(lambda_id) { |
| 41 | return Err(DscError::Parser(t!("functions.lambdaNotFound", name = func_name, id = lambda_id).to_string())); |
| 42 | } |
| 43 | |
| 44 | let lambda = lambdas.get(lambda_id).unwrap(); |
| 45 | if lambda.parameters.is_empty() || lambda.parameters.len() > 2 { |
| 46 | return Err(DscError::Parser(t!("functions.lambdaTooManyParams", name = func_name).to_string())); |
| 47 | } |
| 48 | |
| 49 | Ok(lambdas) |
| 50 | } |
| 51 | |
| 52 | /// Applies a lambda to each element of an array, yielding transformed values. |
| 53 | /// |