flowcode_core/commands/
combine.rs1#[allow(dead_code)] use crate::ast::ArgValue;
4use crate::FCError;
5
6pub fn combine(args: &[ArgValue]) -> Result<f64, FCError> {
9 if args.is_empty() {
10 return Err(FCError::InsufficientData("combine requires at least one argument".to_string()));
11 }
12 let sum: f64 = args.iter().map(|arg| match arg {
13 ArgValue::Number(n) => *n,
14 _ => 0.0, }).sum();
16 Ok(sum)
17}
18
19pub fn combine_with_error_handling(args: &[ArgValue]) -> Result<f64, FCError> {
21 if args.len() < 3 {
22 return Err(FCError::InsufficientData("Expected at least 3 arguments: source1, source2, and on clause".to_string()));
23 }
24
25 let source1 = match args.get(0) {
26 Some(ArgValue::String(s)) => s.clone(),
27 Some(other) => return Err(FCError::InvalidArgument(format!("Expected String for source1, got {:?}", other))),
28 None => return Err(FCError::InsufficientData("Missing source1 data".to_string())),
29 };
30
31 let source2 = match args.get(1) {
32 Some(ArgValue::String(s)) => s.clone(),
33 Some(other) => return Err(FCError::InvalidArgument(format!("Expected String for source2, got {:?}", other))),
34 None => return Err(FCError::InsufficientData("Missing source2 data".to_string())),
35 };
36
37 let on_clause = match args.get(2) {
38 Some(ArgValue::String(s)) => s.clone(),
39 Some(other) => return Err(FCError::InvalidArgument(format!("Expected string for on clause, got {:?}", other))),
40 None => return Err(FCError::InsufficientData("Missing on clause for combination".to_string())),
41 };
42
43 let combined_data = format!("Combined data from {} and {} on {}", source1, source2, on_clause);
45 println!("{}", combined_data); Ok(0.0) }