Array Operators

Array operators in DataLogic-rs are used to work with arrays or lists in JSON data. They help you filter, transform, and analyze array elements.

map
filter
reduce
all
some
none
merge
in

map

The map operator applies a rule to each element in an array and returns an array with the results.

Syntax

{ "map": [array, rule] }

Parameters

Parameter Description
array The array to process
rule The rule to apply to each element

Example: Double each number

Rule:

Data:

Result:

Example: Extract property from objects

Rule:

Data:

Result:

some

The some operator checks if at least one element in an array satisfies a condition.

Syntax

{ "some": [array, condition] }

Parameters

Parameter Description
array The array to check
condition The condition to test each element against

Example: Check if any item has a quantity of 10 or more

Rule:

Data:

Result:

all

The all operator checks if all elements in an array satisfy a condition.

Syntax

{ "all": [array, condition] }

Parameters

Parameter Description
array The array to check
condition The condition to test each element against

Example: Check if all users are adults

Rule:

Data:

Result:

none

The none operator checks if no elements in an array satisfy a condition. It's effectively the opposite of the some operator.

Syntax

{ "none": [array, condition] }

Parameters

Parameter Description
array The array to check
condition The condition to evaluate for each element

Example: Check if none of the values are negative

Rule:

Data:

Result:

Example: Check if none of the items are in stock

Rule:

Data:

Result:

filter

The filter operator creates a new array with all elements that pass a condition.

Syntax

{ "filter": [array, condition] }

Parameters

Parameter Description
array The array to filter
condition The condition each element must satisfy

Example: Filter out even numbers

Rule:

Data:

Result:

Example: Filter for adult users

Rule:

Data:

Result:

Example: Filter Products by Price and Availability

Rule:

Data:

Result:

reduce

The reduce operator applies a function to each element in the array to reduce it to a single value.

Syntax

{ "reduce": [array, accumulator_function, initial_value] }

Parameters

Parameter Description
array The array to reduce
accumulator_function The function to apply to each element and the accumulator
initial_value The initial value of the accumulator

Example: Sum of numbers

Rule:

Data:

Result:

Example: Calculating total order value

Rule:

Data:

Result:

merge

The merge operator combines multiple arrays into a single array.

Syntax

{ "merge": [array1, array2, ...] }

Parameters

Parameter Description
array1, array2, ... Arrays to merge together

Example: Merge multiple arrays

Rule:

Data:

Result:

Example: Merge and flatten nested arrays

Rule:

Data:

Result:

in

The in operator checks if a specific value exists in an array.

Syntax

{ "in": [value, array] }

Parameters

Parameter Description
value The value to search for
array The array to search in

Example: Check if a value is in an array

Rule:

Data:

Result:

Example: Check for permissions

Rule:

Data:

Result:

Array Operators Overview

DataLogic-rs provides powerful array operators that help you work with arrays:

  • map - Transform each element in an array
  • filter - Remove elements that don't match a condition
  • reduce - Combine array elements into a single value
  • all - Check if all elements match a condition
  • some - Check if at least one element matches a condition
  • none - Check if no elements match a condition
  • merge - Combine multiple arrays into one
  • in - Check if a value exists in an array

These operators can be combined to perform complex array operations efficiently.