| 26 | } |
| 27 | |
| 28 | fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> { |
| 29 | debug!("{}", t!("functions.first.invoked")); |
| 30 | |
| 31 | if let Some(array) = args[0].as_array() { |
| 32 | if array.is_empty() { |
| 33 | return Err(DscError::Parser(t!("functions.first.emptyArray").to_string())); |
| 34 | } |
| 35 | return Ok(array[0].clone()); |
| 36 | } |
| 37 | |
| 38 | if let Some(string) = args[0].as_str() { |
| 39 | if string.is_empty() { |
| 40 | return Err(DscError::Parser(t!("functions.first.emptyString").to_string())); |
| 41 | } |
| 42 | return Ok(Value::String(string.chars().next().unwrap().to_string())); |
| 43 | } |
| 44 | |
| 45 | Err(DscError::Parser(t!("functions.first.invalidArgType").to_string())) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #[cfg(test)] |