From 4571f3a5785df02801cbee4e91339d606e6ee961 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 30 Aug 2019 09:16:08 +0300 Subject: [PATCH] Update aggregation operator documentation Relates to #44 --- README.md | 22 +++++++++++++++++++--- src/lib.rs | 22 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b3b415..be5379d 100644 --- a/README.md +++ b/README.md @@ -166,14 +166,30 @@ Supported unary operators: #### The Aggregation Operator -The aggregation operator aggregates two values into a tuple. -If one of the values is a tuple already, the resulting tuple will be flattened. +The aggregation operator aggregates a set of values into a tuple. +A tuple can contain arbitrary values, it is not restricted to a single type. +The operator is n-ary, so it supports creating tuples longer than length two. Example: ```rust use evalexpr::*; -assert_eq!(eval("1, 2, 3"), Ok(Value::from(vec![Value::from(1), Value::from(2), Value::from(3)]))); +assert_eq!(eval("1, \"b\", 3"), Ok(Value::from(vec![Value::from(1), Value::from("b"), Value::from(3)]))); +``` + +To create nested tuples, use parentheses: + +```rust +use evalexpr::*; + +assert_eq!(eval("1, 2, (true, \"b\")"), Ok(Value::from(vec![ + Value::from(1), + Value::from(2), + Value::from(vec![ + Value::from(true), + Value::from("b") + ]) +]))); ``` #### The Assignment Operator diff --git a/src/lib.rs b/src/lib.rs index 72e66b2..b3184d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,14 +153,30 @@ //! //! #### The Aggregation Operator //! -//! The aggregation operator aggregates two values into a tuple. -//! If one of the values is a tuple already, the resulting tuple will be flattened. +//! The aggregation operator aggregates a set of values into a tuple. +//! A tuple can contain arbitrary values, it is not restricted to a single type. +//! The operator is n-ary, so it supports creating tuples longer than length two. //! Example: //! //! ```rust //! use evalexpr::*; //! -//! assert_eq!(eval("1, 2, 3"), Ok(Value::from(vec![Value::from(1), Value::from(2), Value::from(3)]))); +//! assert_eq!(eval("1, \"b\", 3"), Ok(Value::from(vec![Value::from(1), Value::from("b"), Value::from(3)]))); +//! ``` +//! +//! To create nested tuples, use parentheses: +//! +//! ```rust +//! use evalexpr::*; +//! +//! assert_eq!(eval("1, 2, (true, \"b\")"), Ok(Value::from(vec![ +//! Value::from(1), +//! Value::from(2), +//! Value::from(vec![ +//! Value::from(true), +//! Value::from("b") +//! ]) +//! ]))); //! ``` //! //! #### The Assignment Operator