ganit-core 0.1.0

Spreadsheet formula engine — parser and evaluator for Excel-compatible formulas
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::types::Value;

/// `COUNT(value1, ...)` — count of numeric `Value::Number` values only.
/// Ignores Text, Bool, Empty, Error. Returns 0 if called with no args.
pub fn count_fn(args: &[Value]) -> Value {
    let n = args.iter().filter(|v| matches!(v, Value::Number(_))).count();
    Value::Number(n as f64)
}

/// `COUNTA(value1, ...)` — count of non-empty values.
/// Counts Number, Text, Bool, Error — anything except `Value::Empty`.
pub fn counta_fn(args: &[Value]) -> Value {
    let n = args.iter().filter(|v| !matches!(v, Value::Empty)).count();
    Value::Number(n as f64)
}

#[cfg(test)]
mod tests;