Appearance
Collection Operations
Collection operations in the expression language provide powerful mechanisms for testing membership and filtering based on sets of values. This chapter provides a comprehensive overview of collection operations, their syntax, capabilities, and best practices.
in Operator
The in
operator is the primary collection operation, used to test whether a value is present in a given set of values. Its counterpart, NOT IN
, tests for the absence of a value in the set.
Basic Syntax
js
field in (value1, value2, ...)
field NOT in (value1, value2, ...)
Value Types and Type Handling
The in operator supports multiple value types within the same list:
String Values
jsstatus in ("active", "pending", "completed")
Numeric Values
- Integers and floating-point numbers are supported
- All numbers are internally handled as float64
jspriority in (1, 2.5, 3.14)
Mixed Value Types
jsvalue in ("test", 42, "hello", 3.14)
Syntax Flexibility
Optional Commas Both formats are valid:
jsstatus in ("active", "pending", "completed") status in ("active" "pending" "completed")
Single Value Lists
jscategory in ("books")
Empty Lists
jsvalue in () // Always evaluates to false value NOT in () // Always evaluates to true
Edge Cases and Error Handling
Invalid Syntax
js// Missing opening parenthesis - Error status in "active", "pending") // Invalid number format - Error priority in (1, 2.5.5, 3) // Unexpected tokens - Error status in ("test", ==, "value")
Type Mismatches
- The in operator performs strict type checking
- No automatic type conversion between strings and numbers
js// This will not match even if status contains "42" status in (42)
Best Practices
List Organization
js// Preferred: Use commas for better readability status in ("active", "pending", "completed") // Avoid: Space-separated values can be less clear status in ("active" "pending" "completed")
Value Ordering
js// Preferred: Organize similar values together type in ("error", "warning", "critical", 404, 500, 503)
Type Consistency
js// Preferred: Use consistent types when possible priority in (1, 2, 3, 4, 5) status in ("active", "pending", "completed") // Avoid mixing types unless necessary value in ("high", 1, "low", 2)
List Length
js// Consider breaking very long lists into logical groups // Instead of: status in ("pending", "active", "paused", "cancelled", "expired", "deleted", "archived") // Use: (status in ("pending", "active", "paused") OR status in ("cancelled", "expired", "deleted", "archived"))
Implementation Details
The in operator is implemented with the following characteristics:
Value Parsing
- String values are stored as-is
- Numeric values are parsed as float64
- Invalid number formats trigger parsing errors
List Evaluation
- Values are compared using strict equality
- Type checking is performed during comparison
- Empty lists are handled as special cases
Performance Considerations
- Lists are evaluated linearly
- Consider list size impact on performance
- Very large lists might benefit from alternative approaches
Common Use Cases
Status Checking
jsstatus in ("active", "pending")
Error Code Filtering
jscode in (404, 500, 503)
Category Matching
jscategory in ("books", "electronics", "clothing")
Permission Validation
jsrole in ("admin", "moderator", "editor")
Integration with Other Features
With Logical Operators
jsstatus in ("active", "pending") AND priority > 3
With Parentheses
js(status in ("active", "pending") OR priority in (1, 2)) AND category == "urgent"
With NOT Operator
jsstatus NOT in ("deleted", "archived")