Expression
public protocol Expression : SendableUndocumented
-
Default implementationasBoolean()
Casts the expression to a
BooleanExpression.Default Implementation
Declaration
Swift
func asBoolean() -> BooleanExpressionReturn Value
A
BooleanExpressionrepresenting the same expression. -
Default implementationas(_:)
Assigns an alias to this expression.
Aliases are useful for renaming fields in the output of a stage or for giving meaningful names to calculated values.
// Calculate total price and alias it "totalPrice" Field("price").multiply(Field("quantity")).as("totalPrice")Default Implementation
Declaration
Swift
func `as`(_ name: String) -> AliasedExpressionParameters
nameThe alias to assign to this expression.
Return Value
A new
AliasedExpressionwrapping this expression with the alias. -
Default implementationround()
Creates an expression that returns the value of self rounded to the nearest integer.
// Get the value of the "amount" field rounded to the nearest integer. Field("amount").round()Default Implementation
Declaration
Swift
func round() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the rounded number. -
Default implementationsqrt()
Creates an expression that returns the square root of self.
// Get the square root of the "area" field. Field("area").sqrt()Default Implementation
Declaration
Swift
func sqrt() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the square root of the number. -
Default implementationpow(_:)
Creates an expression that returns the value of self raised to the power of self.
Returns zero on underflow.
// Get the value of the "amount" field raised to the power of 2. Field("amount").pow(2)Default Implementation
Declaration
Swift
func pow(_ exponent: Sendable) -> FunctionExpressionParameters
exponentThe exponent to raise self to.
Return Value
A new
FunctionExpressionrepresenting the power of the number. -
Default implementationpow(_:)
Creates an expression that returns the value of self raised to the power of self.
Returns zero on underflow.
// Get the value of the "amount" field raised to the power of the "exponent" field. Field("amount").pow(Field("exponent"))Default Implementation
Declaration
Swift
func pow(_ exponent: Expression) -> FunctionExpressionParameters
exponentThe exponent to raise self to.
Return Value
A new
FunctionExpressionrepresenting the power of the number. -
Default implementationln()
Creates an expression that returns the natural logarithm of self.
// Get the natural logarithm of the "amount" field. Field("amount").ln()Default Implementation
Declaration
Swift
func ln() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the natural logarithm of the number. -
Default implementationfloor()
Creates an expression that returns the largest numeric value that isn't greater than self.
// Get the floor of the "amount" field. Field("amount").floor()Default Implementation
Declaration
Swift
func floor() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the floor of the number. -
Default implementationexp()
Creates an expression that returns e to the power of self.
Returns zero on underflow and nil on overflow.
// Get the exp of the "amount" field. Field("amount").exp()Default Implementation
Declaration
Swift
func exp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the exp of the number. -
Default implementationceil()
Creates an expression that returns the smallest numeric value that isn't less than the number.
// Get the ceiling of the "amount" field. Field("amount").ceil()Default Implementation
Declaration
Swift
func ceil() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the ceiling of the number. -
Default implementationabs()
Creates an expression that returns the absolute value of the number.
// Get the absolute value of the "amount" field. Field("amount").abs()Default Implementation
Declaration
Swift
func abs() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the absolute value of the number. -
Default implementationtrunc()
Creates an expression that returns the value of self truncated to an integer.
// Get the value of the "rating" field truncated to an integer. Field("rating").trunc()Default Implementation
Declaration
Swift
func trunc() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the truncated number. -
Default implementationtruncToPrecision(_:)
Creates an expression that truncates self to a specified number of decimal places.
If
decimalPlaceis positive, truncates number to the right of the decimal point. IfdecimalPlaceis negative, truncates number to the left of the decimal point.// Truncate the value of the "rating" field to 2 decimal places. Field("rating").truncToPrecision(2)Default Implementation
Declaration
Swift
func truncToPrecision(_ decimalPlace: Sendable) -> FunctionExpressionParameters
decimalPlaceThe number of decimal places to truncate to.
Return Value
A new
FunctionExpressionrepresenting the truncated number. -
Default implementationtruncToPrecision(_:)
Creates an expression that truncates self to a specified number of decimal places.
If
decimalPlaceis positive, truncates number to the right of the decimal point. IfdecimalPlaceis negative, truncates number to the left of the decimal point.// Truncate the value of the "rating" field to the number of decimal places specified in the // "precision" field. Field("rating").truncToPrecision(Field("precision"))Default Implementation
Declaration
Swift
func truncToPrecision(_ decimalPlace: Expression) -> FunctionExpressionParameters
decimalPlaceThe number of decimal places to truncate to as an expression.
Return Value
A new
FunctionExpressionrepresenting the truncated number. -
Default implementationadd(_:)
Creates an expression that adds another expression to this expression. To add multiple expressions, chain calls to this method. Assumes
selfand the parameter evaluate to compatible types for addition (e.g., numbers, or string/array concatenation if supported by the specific "add" implementation).// Add the value of the "quantity" field and the "reserve" field. Field("quantity").add(Field("reserve")) // Add multiple numeric fields Field("subtotal").add(Field("tax")).add(Field("shipping"))Default Implementation
Declaration
Swift
func add(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionto add.Return Value
A new
FunctionExpressionrepresenting the addition operation. -
Default implementationadd(_:)
Creates an expression that adds a literal value to this expression. To add multiple literals, chain calls to this method. Assumes
selfand the parameter evaluate to compatible types for addition.// Add 5 to the "count" field Field("count").add(5) // Add multiple literal numbers Field("score").add(10).add(20).add(-5)Default Implementation
Declaration
Swift
func add(_ value: Sendable) -> FunctionExpressionParameters
valueA
Sendableliteral value to add.Return Value
A new
FunctionExpressionrepresenting the addition operation. -
Default implementationsubtract(_:)
Creates an expression that subtracts another expression from this expression. Assumes
selfandotherevaluate to numeric types.// Subtract the "discount" field from the "price" field Field("price").subtract(Field("discount"))Default Implementation
Declaration
Swift
func subtract(_ other: Expression) -> FunctionExpressionParameters
otherThe
Expression(evaluating to a number) to subtract from this expression.Return Value
A new
FunctionExpressionrepresenting the subtraction operation. -
Default implementationsubtract(_:)
Creates an expression that subtracts a literal value from this expression. Assumes
selfevaluates to a numeric type.// Subtract 20 from the value of the "total" field Field("total").subtract(20)Default Implementation
Declaration
Swift
func subtract(_ other: Sendable) -> FunctionExpressionParameters
otherThe
Sendableliteral (numeric) value to subtract from this expression.Return Value
A new
FunctionExpressionrepresenting the subtraction operation. -
Default implementationmultiply(_:)
Creates an expression that multiplies this expression by another expression. To multiply multiple expressions, chain calls to this method. Assumes
selfand the parameter evaluate to numeric types.// Multiply the "quantity" field by the "price" field Field("quantity").multiply(Field("price")) // Multiply "rate" by "time" and "conversionFactor" fields Field("rate").multiply(Field("time")).multiply(Field("conversionFactor"))Default Implementation
Declaration
Swift
func multiply(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionto multiply by.Return Value
A new
FunctionExpressionrepresenting the multiplication operation. -
Default implementationmultiply(_:)
Creates an expression that multiplies this expression by a literal value. To multiply multiple literals, chain calls to this method. Assumes
selfevaluates to a numeric type.// Multiply the "score" by 1.1 Field("score").multiply(1.1) // Multiply "base" by 2 and then by 3.0 Field("base").multiply(2).multiply(3.0)Default Implementation
Declaration
Swift
func multiply(_ value: Sendable) -> FunctionExpressionParameters
valueA
Sendableliteral value to multiply by.Return Value
A new
FunctionExpressionrepresenting the multiplication operation. -
Default implementationdivide(_:)
Creates an expression that divides this expression by another expression. Assumes
selfandotherevaluate to numeric types.// Divide the "total" field by the "count" field Field("total").divide(Field("count"))Default Implementation
Declaration
Swift
func divide(_ other: Expression) -> FunctionExpressionParameters
otherThe
Expression(evaluating to a number) to divide by.Return Value
A new
FunctionExpressionrepresenting the division operation. -
Default implementationdivide(_:)
Creates an expression that divides this expression by a literal value. Assumes
selfevaluates to a numeric type.// Divide the "value" field by 10 Field("value").divide(10)Default Implementation
Declaration
Swift
func divide(_ other: Sendable) -> FunctionExpressionParameters
otherThe
Sendableliteral (numeric) value to divide by.Return Value
A new
FunctionExpressionrepresenting the division operation. -
Default implementationmod(_:)
Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. Assumes
selfandotherevaluate to numeric types.// Calculate the remainder of dividing the "value" field by the "divisor" field Field("value").mod(Field("divisor"))Default Implementation
Declaration
Swift
func mod(_ other: Expression) -> FunctionExpressionParameters
otherThe
Expression(evaluating to a number) to use as the divisor.Return Value
A new
FunctionExpressionrepresenting the modulo operation. -
Default implementationmod(_:)
Creates an expression that calculates the modulo (remainder) of dividing this expression by a literal value. Assumes
selfevaluates to a numeric type.// Calculate the remainder of dividing the "value" field by 10 Field("value").mod(10)Default Implementation
Declaration
Swift
func mod(_ other: Sendable) -> FunctionExpressionParameters
otherThe
Sendableliteral (numeric) value to use as the divisor.Return Value
A new
FunctionExpressionrepresenting the modulo operation. -
Default implementationarrayReverse()
Creates an expression that returns the
inputwith elements in reverse order.// Reverse the "tags" array. Field("tags").arrayReverse()Default Implementation
Declaration
Swift
func arrayReverse() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the reversed array. -
Default implementationarrayConcat(_:)
Creates an expression that concatenates an array expression (from
self) with one or more other array expressions. Assumesselfand all parameters evaluate to arrays.// Combine the "items" array with "otherItems" and "archiveItems" array fields. Field("items").arrayConcat(Field("otherItems"), Field("archiveItems"))Default Implementation
Declaration
Swift
func arrayConcat(_ arrays: [Expression]) -> FunctionExpressionParameters
arraysAn array of at least one
Expression(evaluating to an array) to concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated array. -
Default implementationarrayConcat(_:)
Creates an expression that concatenates an array expression (from
self) with one or more array literals. Assumesselfevaluates to an array.// Combine "tags" (an array field) with ["new", "featured"] and ["urgent"] Field("tags").arrayConcat(["new", "featured"], ["urgent"])Default Implementation
Declaration
Swift
func arrayConcat(_ arrays: [[Sendable]]) -> FunctionExpressionParameters
arraysAn array of at least one
Sendablevalues to concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated array. -
Default implementationarrayContains(_:)
Creates an expression that checks if an array (from
self) contains a specific element expression. Assumesselfevaluates to an array.// Check if "sizes" contains the value from "selectedSize" field Field("sizes").arrayContains(Field("selectedSize"))Default Implementation
Declaration
Swift
func arrayContains(_ element: Expression) -> BooleanExpressionParameters
elementThe
Expressionrepresenting the element to search for in the array.Return Value
A new
BooleanExprrepresenting the "array_contains" comparison. -
Default implementationarrayContains(_:)
Creates an expression that checks if an array (from
self) contains a specific literal element. Assumesselfevaluates to an array.// Check if "colors" array contains "red" Field("colors").arrayContains("red")Default Implementation
Declaration
Swift
func arrayContains(_ element: Sendable) -> BooleanExpressionParameters
elementThe
Sendableliteral element to search for in the array.Return Value
A new
BooleanExprrepresenting the "array_contains" comparison. -
Default implementationarrayContainsAll(_:)
Creates an expression that checks if an array (from
self) contains all the specified element expressions. Assumesselfevaluates to an array.// Check if "candidateSkills" contains all skills from "requiredSkill1" and "requiredSkill2" fields Field("candidateSkills").arrayContainsAll([Field("requiredSkill1"), Field("requiredSkill2")])Default Implementation
Declaration
Swift
func arrayContainsAll(_ values: [Expression]) -> BooleanExpressionParameters
valuesA list of
Expressionelements to check for in the array represented byself.Return Value
A new
BooleanExprrepresenting the "array_contains_all" comparison. -
Default implementationarrayContainsAll(_:)
Creates an expression that checks if an array (from
self) contains all the specified literal elements. Assumesselfevaluates to an array.// Check if "tags" contains both "urgent" and "review" Field("tags").arrayContainsAll(["urgent", "review"])Default Implementation
Declaration
Swift
func arrayContainsAll(_ values: [Sendable]) -> BooleanExpressionParameters
valuesAn array of at least one
Sendableelement to check for in the array.Return Value
A new
BooleanExprrepresenting the "array_contains_all" comparison. -
Default implementationarrayContainsAll(_:)
Creates an expression that checks if an array (from
self) contains all the specified element expressions. Assumesselfevaluates to an array.// Check if the "tags" array contains "foo", "bar", and "baz" Field("tags").arrayContainsAll(Constant(["foo", "bar", "baz"]))Default Implementation
Declaration
Swift
func arrayContainsAll(_ arrayExpression: Expression) -> BooleanExpressionParameters
valuesAn
Expressionelements evaluated to be array.Return Value
A new
BooleanExprrepresenting the "array_contains_all" comparison. -
Default implementationarrayContainsAny(_:)
Creates an expression that checks if an array (from
self) contains any of the specified element expressions. Assumesselfevaluates to an array.// Check if "userGroups" contains any group from "allowedGroup1" or "allowedGroup2" fields Field("userGroups").arrayContainsAny([Field("allowedGroup1"), Field("allowedGroup2")])Default Implementation
Declaration
Swift
func arrayContainsAny(_ values: [Expression]) -> BooleanExpressionParameters
valuesA list of
Expressionelements to check for in the array.Return Value
A new
BooleanExprrepresenting the "array_contains_any" comparison. -
Default implementationarrayContainsAny(_:)
Creates an expression that checks if an array (from
self) contains any of the specified literal elements. Assumesselfevaluates to an array.// Check if "categories" contains either "electronics" or "books" Field("categories").arrayContainsAny(["electronics", "books"])Default Implementation
Declaration
Swift
func arrayContainsAny(_ values: [Sendable]) -> BooleanExpressionParameters
valuesAn array of at least one
Sendableelement to check for in the array.Return Value
A new
BooleanExprrepresenting the "array_contains_any" comparison. -
Default implementationarrayContainsAny(_:)
Creates an expression that checks if an array (from
self) contains any of the specified element expressions. Assumesselfevaluates to an array.// Check if "groups" array contains any of the values from the "userGroup" field Field("groups").arrayContainsAny(Field("userGroup"))Default Implementation
Declaration
Swift
func arrayContainsAny(_ arrayExpression: Expression) -> BooleanExpressionParameters
arrayExpressionAn
Expressionelements evaluated to be array.Return Value
A new
BooleanExprrepresenting the "array_contains_any" comparison. -
Default implementationarrayLength()
Creates an expression that calculates the length of an array. Assumes
selfevaluates to an array.// Get the number of items in the "cart" array Field("cart").arrayLength()Default Implementation
Declaration
Swift
func arrayLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the array. -
Default implementationarrayFilter(alias:filter:)
Filters an array to a subset of elements that match the provided condition. Assumes
selfevaluates to an array.// Filter the "items" array to include elements where "price" > 10 Field("items").arrayFilter(alias: "item", filter: Variable("item.price").greaterThan(10))Default Implementation
Declaration
Swift
func arrayFilter(alias: String, filter: BooleanExpression) -> FunctionExpressionParameters
aliasThe variable name to be used in the filter expression to refer to the current array element.
filterA
BooleanExpressionthat determines whether an element is included.Return Value
A new
FunctionExpressionrepresenting the filtered array. -
Default implementationarrayTransform(elementAlias:transform:)
Creates an expression that applies a provided transformation to each element in an array. Assumes
selfevaluates to an array.// Transform the "scores" array by multiplying the "score" by 2 Field("scores").arrayTransform( elementAlias: "score", transform: Variable("score").multiply(2) )Default Implementation
Declaration
Swift
func arrayTransform(elementAlias: String, transform: Expression) -> FunctionExpressionParameters
elementAliasThe variable name to be used in the transform expression to refer to the current array element.
transformA lambda
Expressionevaluated for each element to determine its new value.Return Value
A new
FunctionExpressionrepresenting the transformed array. -
Default implementationarrayTransformWithIndex(elementAlias:indexAlias:transform:)
Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression. Assumes
selfevaluates to an array.// Transform the "scores" array by adding the element index and "name" Field("scores").arrayTransformWithIndex( elementAlias: "score", indexAlias: "index", transform: Variable("score").add(Variable("index")) )Default Implementation
Declaration
Swift
func arrayTransformWithIndex(elementAlias: String, indexAlias: String, transform: Expression) -> FunctionExpressionParameters
elementAliasThe variable name to be used in the transform expression to refer to the current array element.
indexAliasThe variable name to be used in the transform expression to refer to the current element's zero-based index.
transformA lambda
Expressionevaluated for each element to determine its new value.Return Value
A new
FunctionExpressionrepresenting the transformed array. -
Default implementationarraySlice(offset:)
Returns a subset of the array starting at the given offset. Assumes
selfevaluates to an array.// Get all elements from the "tags" array starting at index 1 Field("tags").arraySlice(offset: 1)Default Implementation
Declaration
Swift
func arraySlice(offset: Int) -> FunctionExpressionParameters
offsetThe starting offset (integer).
Return Value
A new
FunctionExpressionrepresenting the sliced array. -
Default implementationarraySlice(offset:)
Returns a subset of the array starting at the given offset. Assumes
selfevaluates to an array.// Get all elements from "tags" starting at an offset defined by a field Field("tags").arraySlice(offset: Field("startIdx"))Default Implementation
Declaration
Swift
func arraySlice(offset: Expression) -> FunctionExpressionParameters
offsetAn
Expression(evaluating to an integer) for the starting offset.Return Value
A new
FunctionExpressionrepresenting the sliced array. -
Default implementationarraySlice(offset:length:)
Returns a subset of the array starting at the given offset, up to the given length. Assumes
selfevaluates to an array.// Get 2 elements from the "tags" array starting at index 1 Field("tags").arraySlice(offset: 1, length: 2)Default Implementation
Declaration
Swift
func arraySlice(offset: Int, length: Int) -> FunctionExpressionParameters
offsetThe starting offset (integer).
lengthThe maximum length of the subset (positive integer).
Return Value
A new
FunctionExpressionrepresenting the sliced array. -
Default implementationarraySlice(offset:length:)
Returns a subset of the array starting at the given offset, up to the given length. Assumes
selfevaluates to an array.// Get elements using expressions for offset and length Field("tags").arraySlice(offset: Field("startIdx"), length: Field("count"))Default Implementation
Declaration
Swift
func arraySlice(offset: Expression, length: Expression) -> FunctionExpressionParameters
offsetAn
Expression(evaluating to an integer) for the starting offset.lengthAn
Expression(evaluating to a positive integer) for the maximum length.Return Value
A new
FunctionExpressionrepresenting the sliced array. -
Default implementationarraySlice(offset:length:)
Returns a subset of the array starting at the given offset, up to the given length. Assumes
selfevaluates to an array.// Get n elements from the "tags" array starting at index 1 Field("tags").arraySlice(offset: 1, length: Field("count"))Default Implementation
Declaration
Swift
func arraySlice(offset: Int, length: Expression) -> FunctionExpressionParameters
offsetThe starting offset (integer).
lengthAn
Expression(evaluating to a positive integer) for the maximum length.Return Value
A new
FunctionExpressionrepresenting the sliced array. -
Default implementationarraySlice(offset:length:)
Returns a subset of the array starting at the given offset, up to the given length. Assumes
selfevaluates to an array.// Get 2 elements from the "tags" array starting at an offset defined by a field Field("tags").arraySlice(offset: Field("startIdx"), length: 2)Default Implementation
Declaration
Swift
func arraySlice(offset: Expression, length: Int) -> FunctionExpressionParameters
offsetAn
Expression(evaluating to an integer) for the starting offset.lengthThe maximum length of the subset (positive integer).
Return Value
A new
FunctionExpressionrepresenting the sliced array. -
Default implementationarrayFirst()
Creates an expression that returns the first element of an array. Assumes
selfevaluates to an array.// Get the first item in the "tags" array. Field("tags").arrayFirst()Default Implementation
Declaration
Swift
func arrayFirst() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the first element of the array. -
Default implementationarrayFirstN(_:)
Creates an expression that returns the first
nelements of an array. Assumesselfevaluates to an array.// Get the first 3 items in the "tags" array. Field("tags").arrayFirstN(3)Default Implementation
Declaration
Swift
func arrayFirstN(_ n: Int) -> FunctionExpressionParameters
nThe number of elements to return.
Return Value
A new
FunctionExpressionrepresenting the firstnelements of the array. -
Default implementationarrayFirstN(_:)
Creates an expression that returns the first
nelements of an array. Assumesselfevaluates to an array.// Get the first n items in the "tags" array where n is specified by field "count". Field("tags").arrayFirstN(Field("count"))Default Implementation
Declaration
Swift
func arrayFirstN(_ n: Expression) -> FunctionExpressionParameters
nAn
Expression(evaluating to an Int) representing the number of elements to return.Return Value
A new
FunctionExpressionrepresenting the firstnelements of the array. -
Default implementationarrayLast()
Creates an expression that returns the last element of an array. Assumes
selfevaluates to an array.// Get the last item in the "tags" array. Field("tags").arrayLast()Default Implementation
Declaration
Swift
func arrayLast() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the last element of the array. -
Default implementationarrayLastN(_:)
Creates an expression that returns the last
nelements of an array. Assumesselfevaluates to an array.// Get the last 3 items in the "tags" array. Field("tags").arrayLastN(3)Default Implementation
Declaration
Swift
func arrayLastN(_ n: Int) -> FunctionExpressionParameters
nThe number of elements to return.
Return Value
A new
FunctionExpressionrepresenting the lastnelements of the array. -
Default implementationarrayLastN(_:)
Creates an expression that returns the last
nelements of an array. Assumesselfevaluates to an array.// Get the last n items in the "tags" array where n is specified by field "count". Field("tags").arrayLastN(Field("count"))Default Implementation
Declaration
Swift
func arrayLastN(_ n: Expression) -> FunctionExpressionParameters
nAn
Expression(evaluating to an Int) representing the number of elements to return.Return Value
A new
FunctionExpressionrepresenting the lastnelements of the array. -
Default implementationarrayGet(_:)
Creates an expression that accesses an element in an array (from
self) at the specified integer offset. A negative offset starts from the end. If the offset is out of bounds, an error may be returned during evaluation. Assumesselfevaluates to an array.// Return the value in the "tags" field array at index 1. Field("tags").arrayGet(1) // Return the last element in the "tags" field array. Field("tags").arrayGet(-1)Default Implementation
Declaration
Swift
func arrayGet(_ offset: Int) -> FunctionExpressionParameters
offsetThe literal
Intoffset of the element to return.Return Value
A new
FunctionExpressionrepresenting the "arrayGet" operation. -
Default implementationarrayGet(_:)
Creates an expression that accesses an element in an array (from
self) at the offset specified by an expression. A negative offset starts from the end. If the offset is out of bounds, an error may be returned during evaluation. Assumesselfevaluates to an array andoffsetExprevaluates to an integer.// Return the value in the tags field array at index specified by field "favoriteTagIndex". Field("tags").arrayGet(Field("favoriteTagIndex"))Default Implementation
Declaration
Swift
func arrayGet(_ offsetExpression: Expression) -> FunctionExpressionParameters
offsetExpressionAn
Expression(evaluating to an Int) representing the offset of the element to return.Return Value
A new
FunctionExpressionrepresenting the "arrayGet" operation. -
Default implementationarrayIndexOf(_:)
Creates an expression that returns the index of the first occurrence of a value in an array. Returns nil if the value is not found. Assumes
selfevaluates to an array.// Get the index of "urgent" in the "tags" array. Field("tags").arrayIndexOf("urgent")Default Implementation
Declaration
Swift
func arrayIndexOf(_ value: Sendable) -> FunctionExpressionParameters
valueThe literal
Sendablevalue to search for.Return Value
A new
FunctionExpressionrepresenting the index of the value. -
Default implementationarrayIndexOf(_:)
Creates an expression that returns the index of the first occurrence of a value in an array. Returns nil if the value is not found. Assumes
selfevaluates to an array.// Get the index of the value of field "searchTag" in the "tags" array. Field("tags").arrayIndexOf(Field("searchTag"))Default Implementation
Declaration
Swift
func arrayIndexOf(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionrepresenting the value to search for.Return Value
A new
FunctionExpressionrepresenting the index of the value. -
Default implementationarrayLastIndexOf(_:)
Creates an expression that returns the index of the last occurrence of a value in an array. Returns nil if the value is not found. Assumes
selfevaluates to an array.// Get the last index of "urgent" in the "tags" array. Field("tags").arrayLastIndexOf("urgent")Default Implementation
Declaration
Swift
func arrayLastIndexOf(_ value: Sendable) -> FunctionExpressionParameters
valueThe literal
Sendablevalue to search for.Return Value
A new
FunctionExpressionrepresenting the last index of the value. -
Default implementationarrayLastIndexOf(_:)
Creates an expression that returns the index of the last occurrence of a value in an array. Returns nil if the value is not found. Assumes
selfevaluates to an array.// Get the last index of the value of field "searchTag" in the "tags" array. Field("tags").arrayLastIndexOf(Field("searchTag"))Default Implementation
Declaration
Swift
func arrayLastIndexOf(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionrepresenting the value to search for.Return Value
A new
FunctionExpressionrepresenting the last index of the value. -
Default implementationarrayIndexOfAll(_:)
Creates an expression that returns all indices of a value in an array. Returns an empty array if the value is not found. Assumes
selfevaluates to an array.// Get all indices of "urgent" in the "tags" array. Field("tags").arrayIndexOfAll("urgent")Default Implementation
Declaration
Swift
func arrayIndexOfAll(_ value: Sendable) -> FunctionExpressionParameters
valueThe literal
Sendablevalue to search for.Return Value
A new
FunctionExpressionrepresenting the indices of the value. -
Default implementationarrayIndexOfAll(_:)
Creates an expression that returns all indices of a value in an array. Returns an empty array if the value is not found. Assumes
selfevaluates to an array.// Get all indices of the value of field "searchTag" in the "tags" array. Field("tags").arrayIndexOfAll(Field("searchTag"))Default Implementation
Declaration
Swift
func arrayIndexOfAll(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionrepresenting the value to search for.Return Value
A new
FunctionExpressionrepresenting the indices of the value. -
Default implementationarrayMaximum()
Creates an expression that returns the maximum element of an array.
Assumes
selfevaluates to an array.// Get the maximum value in the "scores" array. Field("scores").arrayMaximum()Default Implementation
Declaration
Swift
func arrayMaximum() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the maximum element of the array. -
Default implementationarrayMinimum()
Creates an expression that returns the minimum element of an array.
Assumes
selfevaluates to an array.// Get the minimum value in the "scores" array. Field("scores").arrayMinimum()Default Implementation
Declaration
Swift
func arrayMinimum() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the minimum element of the array. -
Default implementationarrayMinimumN(_:)
Creates an expression that returns the
nsmallest elements of an array. Assumesselfevaluates to an array.// Get the 3 lowest scores in the "scores" array. Field("scores").arrayMinimumN(3)Default Implementation
Declaration
Swift
func arrayMinimumN(_ n: Int) -> FunctionExpressionParameters
nThe number of elements to return.
Return Value
A new
FunctionExpressionrepresenting thensmallest elements of the array. -
Default implementationarrayMinimumN(_:)
Creates an expression that returns the
nsmallest elements of an array. Assumesselfevaluates to an array.// Get the n lowest scores in the "scores" array where n is specified by field "count". Field("scores").arrayMinimumN(Field("count"))Default Implementation
Declaration
Swift
func arrayMinimumN(_ n: Expression) -> FunctionExpressionParameters
nAn
Expression(evaluating to an Int) representing the number of elements to return.Return Value
A new
FunctionExpressionrepresenting thensmallest elements of the array. -
Default implementationarrayMaximumN(_:)
Creates an expression that returns the
nlargest elements of an array. Assumesselfevaluates to an array.// Get the 3 highest scores in the "scores" array. Field("scores").arrayMaximumN(3)Default Implementation
Declaration
Swift
func arrayMaximumN(_ n: Int) -> FunctionExpressionParameters
nThe number of elements to return.
Return Value
A new
FunctionExpressionrepresenting thenlargest elements of the array. -
Default implementationarrayMaximumN(_:)
Creates an expression that returns the
nlargest elements of an array. Assumesselfevaluates to an array.// Get the n highest scores in the "scores" array where n is specified by field "count". Field("scores").arrayMaximumN(Field("count"))Default Implementation
Declaration
Swift
func arrayMaximumN(_ n: Expression) -> FunctionExpressionParameters
nAn
Expression(evaluating to an Int) representing the number of elements to return.Return Value
A new
FunctionExpressionrepresenting thenlargest elements of the array. -
Default implementationgreaterThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than the given expression.Default Implementation
Declaration
Swift
func greaterThan(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationgreaterThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than the given value.Default Implementation
Declaration
Swift
func greaterThan(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationgreaterThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than or equal to the given expression.Default Implementation
Declaration
Swift
func greaterThanOrEqual(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationgreaterThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than or equal to the given value.Default Implementation
Declaration
Swift
func greaterThanOrEqual(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than the given expression.Default Implementation
Declaration
Swift
func lessThan(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than the given value.Default Implementation
Declaration
Swift
func lessThan(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than or equal to the given expression.Default Implementation
Declaration
Swift
func lessThanOrEqual(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than or equal to the given value.Default Implementation
Declaration
Swift
func lessThanOrEqual(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequal(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is equal to the given expression.Default Implementation
Declaration
Swift
func equal(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequal(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is equal to the given value.Default Implementation
Declaration
Swift
func equal(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is not equal to the given expression.Default Implementation
Declaration
Swift
func notEqual(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is not equal to the given value.Default Implementation
Declaration
Swift
func notEqual(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequalAny(_:)
Creates an expression that checks if this expression is equal to any of the provided expression values.
// Check if "categoryID" field is equal to "featuredCategory" or "popularCategory" fields Field("categoryID").equalAny([Field("featuredCategory"), Field("popularCategory")])Default Implementation
Declaration
Swift
func equalAny(_ others: [Expression]) -> BooleanExpressionParameters
othersAn array of at least one
Expressionvalue to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequalAny(_:)
Creates an expression that checks if this expression is equal to any of the provided literal values.
// Check if "category" is "Electronics", "Books", or "Home Goods" Field("category").equalAny(["Electronics", "Books", "Home Goods"])Default Implementation
Declaration
Swift
func equalAny(_ others: [Sendable]) -> BooleanExpressionParameters
othersAn array of at least one
Sendableliteral value to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequalAny(_:)
Creates an expression that checks if this expression is equal to any of the provided expression values.
// Check if "categoryID" field is equal to any of "categoryIDs" fields Field("categoryID").equalAny(Field("categoryIDs"))Default Implementation
Declaration
Swift
func equalAny(_ arrayExpression: Expression) -> BooleanExpressionParameters
arrayExpressionAn
Expressionelements evaluated to be array.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqualAny(_:)
Creates an expression that checks if this expression is not equal to any of the provided expression values.
// Check if "statusValue" is not equal to "archivedStatus" or "deletedStatus" fields Field("statusValue").notEqualAny([Field("archivedStatus"), Field("deletedStatus")])Default Implementation
Declaration
Swift
func notEqualAny(_ others: [Expression]) -> BooleanExpressionParameters
othersAn array of at least one
Expressionvalue to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqualAny(_:)
Creates an expression that checks if this expression is not equal to any of the provided literal values.
// Check if "status" is neither "pending" nor "archived" Field("status").notEqualAny(["pending", "archived"])Default Implementation
Declaration
Swift
func notEqualAny(_ others: [Sendable]) -> BooleanExpressionParameters
othersAn array of at least one
Sendableliteral value to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqualAny(_:)
Creates an expression that checks if this expression is equal to any of the provided expression values.
// Check if "categoryID" field is not equal to any of "categoryIDs" fields Field("categoryID").equalAny(Field("categoryIDs"))Default Implementation
Declaration
Swift
func notEqualAny(_ arrayExpression: Expression) -> BooleanExpressionParameters
arrayExpressionAn
Expressionelements evaluated to be array.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationexists()
Creates an expression that checks if a field exists in the document.
// Check if the document has a field named "phoneNumber" Field("phoneNumber").exists()Default Implementation
Declaration
Swift
func exists() -> BooleanExpressionReturn Value
A new
BooleanExpressionrepresenting the "exists" check. -
Default implementationisError()
Creates an expression that checks if this expression produces an error during evaluation.
// Check if accessing a non-existent array index causes an error Field("myArray").arrayGet(100).isError()Default Implementation
Declaration
Swift
func isError() -> BooleanExpressionReturn Value
A new
BooleanExpressionrepresenting the "isError" check. -
Default implementationisAbsent()
Creates an expression that returns
trueif the result of this expression is absent (e.g., a field does not exist in a map). Otherwise, returnsfalse.// Check if the field `value` is absent. Field("value").isAbsent()Default Implementation
Declaration
Swift
func isAbsent() -> BooleanExpressionReturn Value
A new
BooleanExpressionrepresenting the "isAbsent" check.
-
Default implementationjoin(delimiter:)
Creates an expression that joins the elements of an array of strings with a given separator.
Assumes
selfevaluates to an array of strings.// Join the "tags" array with a ", " separator. Field("tags").join(separator: ", ")Default Implementation
Declaration
Swift
func join(delimiter: String) -> FunctionExpressionParameters
delimiterThe string to use as a delimiter.
Return Value
A new
FunctionExpressionrepresenting the joined string. -
Default implementationsplit(delimiter:)
Creates an expression that splits a string into an array of substrings based on a delimiter.
Default Implementation
Declaration
Swift
func split(delimiter: String) -> FunctionExpressionParameters
delimiterThe string to split on.
Return Value
A new
FunctionExpressionrepresenting the array of substrings. -
Default implementationsplit(delimiter:)
Creates an expression that splits a string into an array of substrings based on a delimiter.
Default Implementation
Declaration
Swift
func split(delimiter: Expression) -> FunctionExpressionParameters
delimiterAn expression that evaluates to a string or bytes to split on.
Return Value
A new
FunctionExpressionrepresenting the array of substrings. -
Default implementationlength()
Creates an expression that returns the length of a string.
// Get the length of the "name" field. Field("name").length()Default Implementation
Declaration
Swift
func length() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the string. -
Default implementationcharLength()
Creates an expression that calculates the character length of a string in UTF-8. Assumes
selfevaluates to a string.// Get the character length of the "name" field in its UTF-8 form. Field("name").charLength()Default Implementation
Declaration
Swift
func charLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the string. -
Default implementationlike(_:)
Creates an expression that performs a case-sensitive string comparison using wildcards against a literal pattern. Assumes
selfevaluates to a string.// Check if the "title" field contains the word "guide" (case-sensitive) Field("title").like("%guide%")Default Implementation
Declaration
Swift
func like(_ pattern: String) -> BooleanExpressionParameters
patternThe literal string pattern to search for. Use "%" as a wildcard.
Return Value
A new
BooleanExpressionrepresenting the "like" comparison. -
Default implementationlike(_:)
Creates an expression that performs a case-sensitive string comparison using wildcards against an expression pattern. Assumes
selfevaluates to a string, andpatternevaluates to a string.// Check if "filename" matches a pattern stored in "patternField" Field("filename").like(Field("patternField"))Default Implementation
Declaration
Swift
func like(_ pattern: Expression) -> BooleanExpressionParameters
patternAn
Expression(evaluating to a string) representing the pattern to search for.Return Value
A new
BooleanExpressionrepresenting the "like" comparison. -
Default implementationregexContains(_:)
Creates an expression that checks if a string (from
self) contains a specified regular expression literal as a substring. Assumesselfevaluates to a string.// Check if "description" contains "example" (case-insensitive) Field("description").regexContains("(?i)example")Default Implementation
Declaration
Swift
func regexContains(_ pattern: String) -> BooleanExpressionParameters
patternThe literal string regular expression to use for the search.
Return Value
A new
BooleanExpressionrepresenting the "regex_contains" comparison. -
Default implementationregexContains(_:)
Creates an expression that checks if a string (from
self) contains a specified regular expression (from an expression) as a substring. Assumesselfevaluates to a string, andpatternevaluates to a string.// Check if "logEntry" contains a pattern from "errorPattern" field Field("logEntry").regexContains(Field("errorPattern"))Default Implementation
Declaration
Swift
func regexContains(_ pattern: Expression) -> BooleanExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to use for the search.Return Value
A new
BooleanExpressionrepresenting the "regex_contains" comparison. -
Default implementationregexFind(_:)
Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes
selfevaluates to a string.// Extract the domain name from an email field Field("email").regexFind("@[A-Za-z0-9.-]+")Default Implementation
Declaration
Swift
func regexFind(_ pattern: String) -> FunctionExpressionParameters
patternThe literal string regular expression to search for.
Return Value
A new
FunctionExpressionrepresenting the regular expression find function. -
Default implementationregexFind(_:)
Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes
selfevaluates to a string, andpatternevaluates to a string.// Extract a substring based on a dynamic pattern stored in another field Field("email").regexFind(Field("pattern"))Default Implementation
Declaration
Swift
func regexFind(_ pattern: Expression) -> FunctionExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to search for.Return Value
A new
FunctionExpressionrepresenting the regular expression find function. -
Default implementationregexFindAll(_:)
Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes
selfevaluates to a string.// Extract all hashtags from a post content field Field("content").regexFindAll("#[A-Za-z0-9_]+")Default Implementation
Declaration
Swift
func regexFindAll(_ pattern: String) -> FunctionExpressionParameters
patternThe literal string regular expression to search for.
Return Value
A new
FunctionExpressionthat evaluates to an array of matched substrings. -
Default implementationregexFindAll(_:)
Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes
selfevaluates to a string, andpatternevaluates to a string.// Extract all matches based on a dynamic pattern stored in another field Field("content").regexFindAll(Field("pattern"))Default Implementation
Declaration
Swift
func regexFindAll(_ pattern: Expression) -> FunctionExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to search for.Return Value
A new
FunctionExpressionthat evaluates to an array of matched substrings. -
Default implementationregexMatch(_:)
Creates an expression that checks if a string (from
self) matches a specified regular expression literal entirely. Assumesselfevaluates to a string.// Check if the "email" field matches a valid email pattern Field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")Default Implementation
Declaration
Swift
func regexMatch(_ pattern: String) -> BooleanExpressionParameters
patternThe literal string regular expression to use for the match.
Return Value
A new
BooleanExpressionrepresenting the regular expression match. -
Default implementationregexMatch(_:)
Creates an expression that checks if a string (from
self) matches a specified regular expression (from an expression) entirely. Assumesselfevaluates to a string, andpatternevaluates to a string.// Check if "input" matches the regex stored in "validationRegex" Field("input").regexMatch(Field("validationRegex"))Default Implementation
Declaration
Swift
func regexMatch(_ pattern: Expression) -> BooleanExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to use for the match.Return Value
A new
BooleanExpressionrepresenting the regular expression match. -
Default implementationstringContains(_:)
Creates an expression that checks if a string (from
self) contains a specified literal substring (case-sensitive). Assumesselfevaluates to a string.// Check if the "description" field contains "example". Field("description").stringContains("example")Default Implementation
Declaration
Swift
func stringContains(_ substring: String) -> BooleanExpressionParameters
substringThe literal string substring to search for.
Return Value
A new
BooleanExpressionrepresenting the "stringContains" comparison. -
Default implementationstringContains(_:)
Creates an expression that checks if a string (from
self) contains a specified substring from an expression (case-sensitive). Assumesselfevaluates to a string, andexpressionevaluates to a string.// Check if the "message" field contains the value of the "keyword" field. Field("message").stringContains(Field("keyword"))Default Implementation
Declaration
Swift
func stringContains(_ expression: Expression) -> BooleanExpressionParameters
expressionAn
Expression(evaluating to a string) representing the substring to search for.Return Value
A new
BooleanExpressionrepresenting the "str_contains" comparison. -
Default implementationstartsWith(_:)
Creates an expression that checks if a string (from
self) starts with a given literal prefix (case-sensitive). Assumesselfevaluates to a string.// Check if the "name" field starts with "Mr." Field("name").startsWith("Mr.")Default Implementation
Declaration
Swift
func startsWith(_ prefix: String) -> BooleanExpressionParameters
prefixThe literal string prefix to check for.
Return Value
A new
BooleanExprrepresenting the "starts_with" comparison. -
Default implementationstartsWith(_:)
Creates an expression that checks if a string (from
self) starts with a given prefix from an expression (case-sensitive). Assumesselfevaluates to a string, andprefixevaluates to a string.// Check if "fullName" starts with the value of "firstName" Field("fullName").startsWith(Field("firstName"))Default Implementation
Declaration
Swift
func startsWith(_ prefix: Expression) -> BooleanExpressionParameters
prefixAn
Expression(evaluating to a string) representing the prefix to check for.Return Value
A new
BooleanExprrepresenting the "starts_with" comparison. -
Default implementationendsWith(_:)
Creates an expression that checks if a string (from
self) ends with a given literal suffix (case-sensitive). Assumesselfevaluates to a string.// Check if the "filename" field ends with ".txt" Field("filename").endsWith(".txt")Default Implementation
Declaration
Swift
func endsWith(_ suffix: String) -> BooleanExpressionParameters
suffixThe literal string suffix to check for.
Return Value
A new
BooleanExprrepresenting the "ends_with" comparison. -
Default implementationendsWith(_:)
Creates an expression that checks if a string (from
self) ends with a given suffix from an expression (case-sensitive). Assumesselfevaluates to a string, andsuffixevaluates to a string.// Check if "url" ends with the value of "extension" field Field("url").endsWith(Field("extension"))Default Implementation
Declaration
Swift
func endsWith(_ suffix: Expression) -> BooleanExpressionParameters
suffixAn
Expression(evaluating to a string) representing the suffix to check for.Return Value
A new
BooleanExpressionrepresenting the "ends_with" comparison. -
Default implementationtoLower()
Creates an expression that converts a string (from
self) to lowercase. Assumesselfevaluates to a string.// Convert the "name" field to lowercase Field("name").toLower()Default Implementation
Declaration
Swift
func toLower() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the lowercase string. -
Default implementationtoUpper()
Creates an expression that converts a string (from
self) to uppercase. Assumesselfevaluates to a string.// Convert the "title" field to uppercase Field("title").toUpper()Default Implementation
Declaration
Swift
func toUpper() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the uppercase string. -
Default implementationtrim()
Creates an expression that removes leading and trailing whitespace from a string.
Assumes
selfevaluates to a string.// Trim leading/trailing whitespace from the "comment" field. Field("comment").trim()Default Implementation
Declaration
Swift
func trim() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the trimmed string. -
Default implementationtrim(_:)
Creates an expression that removes leading and trailing occurrences of specified characters from a string (from
self). Assumesselfevaluates to a string, andvalueevaluates to a string.// Trim leading/trailing "xy" from field Field("code").trim(characters: "xy")Default Implementation
Declaration
Swift
func trim(_ value: String) -> FunctionExpressionParameters
valueA
Stringcontaining the characters to trim.Return Value
A new
FunctionExpressionrepresenting the trimmed string. -
Default implementationtrim(_:)
Creates an expression that removes leading and trailing occurrences of specified string (from an expression) from a string (from
self). Assumesselfevaluates to a string, andvalueevaluates to a string.// Trim characters specified by the "trimChars" field from "data" Field("data").trim(characters: Field("trimChars"))Default Implementation
Declaration
Swift
func trim(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expression(evaluating to a string) containing the characters to trim.Return Value
A new
FunctionExpressionrepresenting the trimmed string. -
Default implementationltrim()
Creates an expression that removes leading whitespace from this string expression. Assumes
selfevaluates to a string.// Trim leading whitespace from the "text" field. Field("text").ltrim()Default Implementation
Declaration
Swift
func ltrim() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the ltrim operation. -
Default implementationltrim(_:)
Creates an expression that removes specified leading characters from this string expression. Assumes
selfevaluates to a string, andvalueevaluates to a string.The characters in
valueare treated as a set of characters to trim, not as a substring.// Trim all leading '-' or '_' characters from the "text" field. Field("text").ltrim("-_")Default Implementation
Declaration
Swift
func ltrim(_ value: String) -> FunctionExpressionParameters
valueThe literal string of characters to remove.
Return Value
A new
FunctionExpressionrepresenting the ltrim operation. -
Default implementationltrim(_:)
Creates an expression that removes specified leading characters from this string expression. Assumes
selfevaluates to a string, andvalueevaluates to a string.The characters in
valueare treated as a set of characters to trim, not as a substring.// Trim leading characters defined by the "chars" field from the "text" field. Field("text").ltrim(Field("chars"))Default Implementation
Declaration
Swift
func ltrim(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expression(evaluating to a string) representing the characters to remove.Return Value
A new
FunctionExpressionrepresenting the ltrim operation. -
Default implementationrtrim()
Creates an expression that removes trailing whitespace from this string expression. Assumes
selfevaluates to a string.// Trim trailing whitespace from the "text" field. Field("text").rtrim()Default Implementation
Declaration
Swift
func rtrim() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the rtrim operation. -
Default implementationrtrim(_:)
Creates an expression that removes specified trailing characters from this string expression. Assumes
selfevaluates to a string, andvalueevaluates to a string.The characters in
valueare treated as a set of characters to trim, not as a substring.// Trim trailing '-' or '_' characters from the "text" field. Field("text").rtrim("-_")Default Implementation
Declaration
Swift
func rtrim(_ value: String) -> FunctionExpressionParameters
valueThe literal string of characters to remove.
Return Value
A new
FunctionExpressionrepresenting the rtrim operation. -
Default implementationrtrim(_:)
Creates an expression that removes specified trailing characters from this string expression. Assumes
selfevaluates to a string, andvalueevaluates to a string.The characters in
valueare treated as a set of characters to trim, not as a substring.// Trim trailing characters defined by the "chars" field from the "text" field. Field("text").rtrim(Field("chars"))Default Implementation
Declaration
Swift
func rtrim(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expression(evaluating to a string) representing the characters to remove.Return Value
A new
FunctionExpressionrepresenting the rtrim operation. -
Default implementationstringRepeat(_:)
Creates an expression that repeats this string expression a given number of times. Assumes
selfevaluates to a string.// Repeat the "name" field 3 times. Field("name").stringRepeat(3)Default Implementation
Declaration
Swift
func stringRepeat(_ count: Int) -> FunctionExpressionParameters
countThe literal
Intnumber of times to repeat the string.Return Value
A new
FunctionExpressionrepresenting the stringRepeat operation. -
Default implementationstringRepeat(_:)
Creates an expression that repeats this string expression a given number of times. Assumes
selfevaluates to a string.// Repeat the "name" field the number of times specified in the "count" field. Field("name").stringRepeat(Field("count"))Default Implementation
Declaration
Swift
func stringRepeat(_ count: Expression) -> FunctionExpressionParameters
countAn
Expression(evaluating to an Int) representing the number of times to repeat the string.Return Value
A new
FunctionExpressionrepresenting the stringRepeat operation. -
Default implementationstringReplaceAll(_:with:)
Creates an expression that replaces all occurrences of a literal substring with another literal string. Assumes
selfevaluates to a string.// Replace all occurrences of "cat" with "dog" in the "text" field. Field("text").stringReplaceAll("cat", with: "dog")Default Implementation
Declaration
Swift
func stringReplaceAll(_ oldValue: String, with newValue: String) -> FunctionExpressionParameters
oldValueThe literal string substring to replace.
newValueThe literal replacement string.
Return Value
A new
FunctionExpressionrepresenting the stringReplaceAll operation. -
Default implementationstringReplaceAll(_:with:)
Creates an expression that replaces all occurrences of a substring (from an expression) with another string. Assumes
selfevaluates to a string.// Replace all occurrences of the "old" field with the "new" field in "text". Field("text").stringReplaceAll(Field("old"), with: Field("new"))Default Implementation
Declaration
Swift
func stringReplaceAll(_ oldValue: Expression, with newValue: Expression) -> FunctionExpressionParameters
oldValueAn
Expression(evaluating to a string) representing the substring to replace.newValueAn
Expression(evaluating to a string) representing the replacement string.Return Value
A new
FunctionExpressionrepresenting the stringReplaceAll operation. -
Default implementationstringReplaceOne(_:with:)
Creates an expression that replaces the first occurrence of a literal substring with another literal string. Assumes
selfevaluates to a string.// Replace the first occurrence of "cat" with "dog" in the "text" field. Field("text").stringReplaceOne("cat", with: "dog")Default Implementation
Declaration
Swift
func stringReplaceOne(_ oldValue: String, with newValue: String) -> FunctionExpressionParameters
oldValueThe literal string substring to replace.
newValueThe literal replacement string.
Return Value
A new
FunctionExpressionrepresenting the stringReplaceOne operation. -
Default implementationstringReplaceOne(_:with:)
Creates an expression that replaces the first occurrence of a substring (from an expression) with another string. Assumes
selfevaluates to a string.// Replace the first occurrence of the "old" field with the "new" field in "text". Field("text").stringReplaceOne(Field("old"), with: Field("new"))Default Implementation
Declaration
Swift
func stringReplaceOne(_ oldValue: Expression, with newValue: Expression) -> FunctionExpressionParameters
oldValueAn
Expression(evaluating to a string) representing the substring to replace.newValueAn
Expression(evaluating to a string) representing the replacement string.Return Value
A new
FunctionExpressionrepresenting the stringReplaceOne operation. -
Default implementationstringIndexOf(_:)
Creates an expression that returns the 0-based index of the first occurrence of a literal substring. Assumes
selfevaluates to a string.// Get the index of "world" within the "text" field. Field("text").stringIndexOf("world")Default Implementation
Declaration
Swift
func stringIndexOf(_ substring: String) -> FunctionExpressionParameters
substringThe literal string substring to search for.
Return Value
A new
FunctionExpressionrepresenting the stringIndexOf operation. -
Default implementationstringIndexOf(_:)
Creates an expression that returns the 0-based index of the first occurrence of a substring (from an expression). Assumes
selfevaluates to a string.// Get the index of the "search" field within the "text" field. Field("text").stringIndexOf(Field("search"))Default Implementation
Declaration
Swift
func stringIndexOf(_ substring: Expression) -> FunctionExpressionParameters
substringAn
Expression(evaluating to a string) representing the substring to search for.Return Value
A new
FunctionExpressionrepresenting the stringIndexOf operation. -
Default implementationstringConcat(_:)
Creates an expression that concatenates this string expression with other string expressions. Assumes
selfand all parameters evaluate to strings.// Combine "firstName", " ", and "lastName" Field("firstName").stringConcat([" ", Field("lastName")])Default Implementation
Declaration
Swift
func stringConcat(_ strings: [Sendable]) -> FunctionExpressionParameters
stringsAn array of
ExpressionorStringto concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated string. -
Default implementationstringConcat(_:)
Creates an expression that concatenates this string expression with other string expressions. Assumes
selfand all parameters evaluate to strings.// Combine "firstName", "middleName", and "lastName" fields Field("firstName").stringConcat(Field("middleName"), Field("lastName"))Default Implementation
Declaration
Swift
func stringConcat(_ strings: [Expression]) -> FunctionExpressionParameters
secondStringAn
Expression(evaluating to a string) to concatenate.otherStringsOptional additional
Expression(evaluating to strings) to concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated string. -
Default implementationreverse()
Creates an expression that reverses this expression. Assumes
selfevaluates to a string.// Reverse the value of the "myString" field. Field("myString").reverse()Default Implementation
Declaration
Swift
func reverse() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the reversed string. -
Default implementationstringReverse()
Creates an expression that reverses this string expression. Assumes
selfevaluates to a string.// Reverse the value of the "myString" field. Field("myString").stringReverse()Default Implementation
Declaration
Swift
func stringReverse() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the reversed string. -
Default implementationbyteLength()
Creates an expression that calculates the length of this string or bytes expression in bytes. Assumes
selfevaluates to a string or bytes.// Calculate the length of the "myString" field in bytes. Field("myString").byteLength() // Calculate the size of the "avatar" (Data/Bytes) field. Field("avatar").byteLength()Default Implementation
Declaration
Swift
func byteLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length in bytes. -
Default implementationsubstring(position:length:)
Creates an expression that returns a substring of this expression (String or Bytes) using literal integers for position and optional length. Indexing is 0-based. Assumes
selfevaluates to a string or bytes.// Get substring from index 5 with length 10 Field("myString").substring(5, 10) // Get substring from "myString" starting at index 3 to the end Field("myString").substring(3) // Default nilDefault Implementation
Declaration
Swift
func substring(position: Int, length: Int?) -> FunctionExpressionParameters
positionLiteral
Intindex of the first character/byte.lengthOptional literal
Intlength of the substring. Ifnil, goes to the end.Return Value
A new
FunctionExpressionrepresenting the substring. -
Default implementationsubstring(position:length:)
Creates an expression that returns a substring of this expression (String or Bytes) using expressions for position and optional length. Indexing is 0-based. Assumes
selfevaluates to a string or bytes, and parameters evaluate to integers.// Get substring from index calculated by Field("start") with length from Field("len") Field("myString").substring(Field("start"), Field("len")) // Get substring from index calculated by Field("start") to the end Field("myString").substring(Field("start")) // Default nil for optional Expression lengthDefault Implementation
Declaration
Swift
func substring(position: Expression, length: Expression?) -> FunctionExpressionParameters
positionAn
Expression(evaluating to an Int) for the index of the first character.lengthOptional
Expression(evaluating to an Int) for the length of the substring. Ifnil, goes to the end.Return Value
A new
FunctionExpressionrepresenting the substring.
-
Default implementationgetField(_:)
Creates an expression that accesses a field on this expression using a string key.
Default Implementation
Creates an expression that accesses a field on this expression using a string key.
Declaration
Swift
func getField(_ key: String) -> FunctionExpressionParameters
keyThe string key to access.
Return Value
A new
FunctionExpressionrepresenting the field access. -
Default implementationgetField(_:)
Creates an expression that accesses a field on this expression using a dynamic key expression.
Default Implementation
Creates an expression that accesses a field on this expression using a dynamic key expression.
Declaration
Swift
func getField(_ expression: Expression) -> FunctionExpressionParameters
expressionThe expression evaluating to a key to access.
Return Value
A new
FunctionExpressionrepresenting the field access. -
Default implementationmapGet(_:)
Accesses a value from a map (object) field using the provided literal string key. Assumes
selfevaluates to a Map.// Get the "city" value from the "address" map field Field("address").mapGet("city")Default Implementation
Declaration
Swift
func mapGet(_ subfield: String) -> FunctionExpressionParameters
subfieldThe literal string key to access in the map.
Return Value
A new
FunctionExpressionrepresenting the value associated with the given key. -
Default implementationmapRemove(_:)
Creates an expression that removes a key (specified by a literal string) from the map produced by evaluating this expression. Assumes
selfevaluates to a Map.// Removes the key "baz" from the map held in field "myMap" Field("myMap").mapRemove("baz")Default Implementation
Declaration
Swift
func mapRemove(_ key: String) -> FunctionExpressionParameters
keyThe literal string key to remove from the map.
Return Value
A new
FunctionExpressionrepresenting the "map_remove" operation. -
Default implementationmapRemove(_:)
Creates an expression that removes a key (specified by an expression) from the map produced by evaluating this expression. Assumes
selfevaluates to a Map, andkeyExpressionevaluates to a string.// Removes the key specified by field "keyToRemove" from the map in "settings" Field("settings").mapRemove(Field("keyToRemove"))Default Implementation
Declaration
Swift
func mapRemove(_ keyExpression: Expression) -> FunctionExpressionParameters
keyExpressionAn
Expression(evaluating to a string) representing the key to remove from the map.Return Value
A new
FunctionExpressionrepresenting the "map_remove" operation. -
Default implementationmapMerge(_:)
Creates an expression that merges this map with multiple other map literals. Assumes
selfevaluates to a Map. Later maps overwrite keys from earlier maps.// Merge "settings" field with { "enabled": true } and another map literal { "priority": 1 } Field("settings").mapMerge(["enabled": true], ["priority": 1])Default Implementation
Declaration
Swift
func mapMerge(_ maps: [[String: Sendable]]) -> FunctionExpressionParameters
mapsMaps (dictionary literals with
Sendablevalues) to merge.Return Value
A new
FunctionExpressionrepresenting the "map_merge" operation. -
Default implementationmapMerge(_:)
Creates an expression that merges this map with multiple other map expressions. Assumes
selfand other arguments evaluate to Maps. Later maps overwrite keys from earlier maps.// Merge "baseSettings" field with "userOverrides" field and "adminConfig" field Field("baseSettings").mapMerge(Field("userOverrides"), Field("adminConfig"))Default Implementation
Declaration
Swift
func mapMerge(_ maps: [Expression]) -> FunctionExpressionParameters
mapsAdditional
Expression(evaluating to Maps) to merge.Return Value
A new
FunctionExpressionrepresenting the "map_merge" operation. -
Default implementationmapSet(_:_:_:)
Creates an expression that returns a new map with the specified entries added or updated. Assumes
selfevaluates to a Map.- Only performs shallow updates to the map.
- Setting a value to
nilwill retain the key with anilvalue. To remove a key entirely, usemapRemove.
// Set the 'category' key to the value of the 'newCategory' field. Field("metadata").mapSet(Field("keyField"), Field("newCategory"))Default Implementation
Declaration
Swift
func mapSet(_ key: Expression, _ value: Expression, _ moreKeyValues: Expression...) -> FunctionExpressionParameters
keyAn
Expressionrepresenting the key to set.valueAn
Expressionrepresenting the value to set.moreKeyValuesAdditional alternating key-value
Expressionpairs to set.Return Value
A new
FunctionExpressionrepresenting the map with the entries set. -
Default implementationmapSet(_:_:_:)
Creates an expression that returns a new map with the specified entries added or updated. Assumes
selfevaluates to a Map.- Only performs shallow updates to the map.
- Setting a value to
nilwill retain the key with anilvalue. To remove a key entirely, usemapRemove.
// Set the 'category' key to "Electronics" and 'active' to true. Field("metadata").mapSet("category", "Electronics", "active", true)Default Implementation
Declaration
Swift
func mapSet(_ key: String, _ value: Sendable, _ moreKeyValues: Sendable...) -> FunctionExpressionParameters
keyA literal string key to set.
valueA
Sendablevalue to set.moreKeyValuesAdditional alternating key-value
Sendablepairs to set.Return Value
A new
FunctionExpressionrepresenting the map with the entries set. -
Default implementationmapKeys()
Creates an expression that returns the keys of this map expression. Assumes
selfevaluates to a Map.While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
// Get the keys of the 'metadata' map field. Field("metadata").mapKeys()Default Implementation
Declaration
Swift
func mapKeys() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the keys of the map. -
Default implementationmapValues()
Creates an expression that returns the values of this map expression. Assumes
selfevaluates to a Map.While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
// Get the values of the 'metadata' map field. Field("metadata").mapValues()Default Implementation
Declaration
Swift
func mapValues() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the values of the map. -
Default implementationmapEntries()
Creates an expression that returns the entries of this map expression as an array of maps, where each map contains a "k" property for the key and a "v" property for the value. Assumes
selfevaluates to a Map.While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
// Get the entries of the 'metadata' map field. Field("metadata").mapEntries()Default Implementation
Declaration
Swift
func mapEntries() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the entries of the map.
-
Default implementationcountDistinct()
Creates an aggregation that counts the number of distinct values of this expression.
// Count the number of distinct categories. Field("category").countDistinct().as("distinctCategories")Default Implementation
Declaration
Swift
func countDistinct() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "count_distinct" aggregation. -
Default implementationcount()
Creates an aggregation that counts the number of stage inputs where this expression evaluates to a valid, non-null value.
// Count the total number of products with a "productId" Field("productId").count().alias("totalProducts")Default Implementation
Declaration
Swift
func count() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "count" aggregation on this expression. -
Default implementationsum()
Creates an aggregation that calculates the sum of this numeric expression across multiple stage inputs. Assumes
selfevaluates to a numeric type.// Calculate the total revenue from a set of orders Field("orderAmount").sum().alias("totalRevenue")Default Implementation
Declaration
Swift
func sum() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "sum" aggregation. -
Default implementationaverage()
Creates an aggregation that calculates the average (mean) of this numeric expression across multiple stage inputs. Assumes
selfevaluates to a numeric type.// Calculate the average age of users Field("age").average().as("averageAge")Default Implementation
Declaration
Swift
func average() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "average" aggregation. -
Default implementationminimum()
Creates an aggregation that finds the minimum value of this expression across multiple stage inputs.
// Find the lowest price of all products Field("price").minimum().alias("lowestPrice")Default Implementation
Declaration
Swift
func minimum() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "min" aggregation. -
Default implementationmaximum()
Creates an aggregation that finds the maximum value of this expression across multiple stage inputs.
// Find the highest score in a leaderboard Field("score").maximum().alias("highestScore")Default Implementation
Declaration
Swift
func maximum() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "max" aggregation. -
Default implementationfirst()
Creates an aggregation that finds the first value of this expression across multiple stage inputs.
// Find the first rating Field("rating").first().as("firstRating")Default Implementation
Declaration
Swift
func first() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "first" aggregation. -
Default implementationlast()
Creates an aggregation that finds the last value of this expression across multiple stage inputs.
// Find the last rating Field("rating").last().as("lastRating")Default Implementation
Declaration
Swift
func last() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "last" aggregation. -
Default implementationarrayAgg()
Creates an aggregation that collects all values of this expression across multiple stage inputs into an array.
If the expression resolves to an absent value, it is converted to
null. The order of elements in the output array is not stable and shouldn't be relied upon.// Collect all tags into an array Field("tags").arrayAgg().as("allTags")Default Implementation
Declaration
Swift
func arrayAgg() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "array_agg" aggregation. -
Default implementationarrayAggDistinct()
Creates an aggregation that collects all distinct values of this expression across multiple stage inputs into an array.
If the expression resolves to an absent value, it is converted to
null. The order of elements in the output array is not stable and shouldn't be relied upon.// Collect all distinct tags into an array Field("tags").arrayAggDistinct().as("allDistinctTags")Default Implementation
Declaration
Swift
func arrayAggDistinct() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the "array_agg_distinct" aggregation. -
Default implementationlogicalMaximum(_:)
Creates an expression that returns the larger value between this expression and other expressions, based on Firestore"s value type ordering.
// Returns the largest of "val1", "val2", and "val3" fields Field("val1").logicalMaximum(Field("val2"), Field("val3"))Default Implementation
Declaration
Swift
func logicalMaximum(_ expressions: [Expression]) -> FunctionExpressionParameters
expressionsAn array of at least one
Expressionto compare with.Return Value
A new
FunctionExpressionrepresenting the logical max operation. -
Default implementationlogicalMaximum(_:)
Creates an expression that returns the larger value between this expression and other literal values, based on Firestore"s value type ordering.
// Returns the largest of "val1" (a field), 100, and 200.0 Field("val1").logicalMaximum(100, 200.0)Default Implementation
Declaration
Swift
func logicalMaximum(_ values: [Sendable]) -> FunctionExpressionParameters
valuesAn array of at least one
Sendablevalue to compare with.Return Value
A new
FunctionExpressionrepresenting the logical max operation. -
Default implementationlogicalMinimum(_:)
Creates an expression that returns the smaller value between this expression and other expressions, based on Firestore"s value type ordering.
// Returns the smallest of "val1", "val2", and "val3" fields Field("val1").logicalMinimum(Field("val2"), Field("val3"))Default Implementation
Declaration
Swift
func logicalMinimum(_ expressions: [Expression]) -> FunctionExpressionParameters
expressionsAn array of at least one
Expressionto compare with.Return Value
A new
FunctionExpressionrepresenting the logical min operation. -
Default implementationlogicalMinimum(_:)
Creates an expression that returns the smaller value between this expression and other literal values, based on Firestore"s value type ordering.
// Returns the smallest of "val1" (a field), 0, and -5.5 Field("val1").logicalMinimum(0, -5.5)Default Implementation
Declaration
Swift
func logicalMinimum(_ values: [Sendable]) -> FunctionExpressionParameters
valuesAn array of at least one
Sendablevalue to compare with.Return Value
A new
FunctionExpressionrepresenting the logical min operation.
-
Default implementationvectorLength()
Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression. Assumes
selfevaluates to a Vector.// Get the vector length (dimension) of the field "embedding". Field("embedding").vectorLength()Default Implementation
Declaration
Swift
func vectorLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the vector. -
Default implementationcosineDistance(_:)
Calculates the cosine distance between this vector expression and another vector expression. Assumes both
selfandotherevaluate to Vectors.// Cosine distance between "userVector" field and "itemVector" field Field("userVector").cosineDistance(Field("itemVector"))Default Implementation
Declaration
Swift
func cosineDistance(_ expression: Expression) -> FunctionExpressionParameters
expressionThe other vector as an
Exprto compare against.Return Value
A new
FunctionExpressionrepresenting the cosine distance. -
Default implementationcosineDistance(_:)
Calculates the cosine distance between this vector expression and another vector literal (
VectorValue). Assumesselfevaluates to a Vector.// Cosine distance with a VectorValue let targetVector = VectorValue(vector: [0.1, 0.2, 0.3]) Field("docVector").cosineDistance(targetVector)Default Implementation
Declaration
Swift
func cosineDistance(_ vector: VectorValue) -> FunctionExpressionParameters
vectorThe other vector as a
VectorValueto compare against.Return Value
A new
FunctionExpressionrepresenting the cosine distance. -
Default implementationcosineDistance(_:)
Calculates the cosine distance between this vector expression and another vector literal (
[Double]). Assumesselfevaluates to a Vector.// Cosine distance between "location" field and a target location Field("location").cosineDistance([37.7749, -122.4194])Default Implementation
Declaration
Swift
func cosineDistance(_ vector: [Double]) -> FunctionExpressionParameters
vectorThe other vector as
[Double]to compare against.Return Value
A new
FunctionExpressionrepresenting the cosine distance. -
Default implementationdotProduct(_:)
Calculates the dot product between this vector expression and another vector expression. Assumes both
selfandotherevaluate to Vectors.// Dot product between "vectorA" and "vectorB" fields Field("vectorA").dotProduct(Field("vectorB"))Default Implementation
Declaration
Swift
func dotProduct(_ expression: Expression) -> FunctionExpressionParameters
expressionThe other vector as an
Exprto calculate with.Return Value
A new
FunctionExpressionrepresenting the dot product. -
Default implementationdotProduct(_:)
Calculates the dot product between this vector expression and another vector literal (
VectorValue). Assumesselfevaluates to a Vector.// Dot product with a VectorValue let weightVector = VectorValue(vector: [0.5, -0.5]) Field("features").dotProduct(weightVector)Default Implementation
Declaration
Swift
func dotProduct(_ vector: VectorValue) -> FunctionExpressionParameters
vectorThe other vector as a
VectorValueto calculate with.Return Value
A new
FunctionExpressionrepresenting the dot product. -
Default implementationdotProduct(_:)
Calculates the dot product between this vector expression and another vector literal (
[Double]). Assumesselfevaluates to a Vector.// Dot product between a feature vector and a target vector literal Field("features").dotProduct([0.5, 0.8, 0.2])Default Implementation
Declaration
Swift
func dotProduct(_ vector: [Double]) -> FunctionExpressionParameters
vectorThe other vector as
[Double]to calculate with.Return Value
A new
FunctionExpressionrepresenting the dot product. -
Default implementationeuclideanDistance(_:)
Calculates the Euclidean distance between this vector expression and another vector expression. Assumes both
selfandotherevaluate to Vectors.// Euclidean distance between "pointA" and "pointB" fields Field("pointA").euclideanDistance(Field("pointB"))Default Implementation
Declaration
Swift
func euclideanDistance(_ expression: Expression) -> FunctionExpressionParameters
expressionThe other vector as an
Exprto compare against.Return Value
A new
FunctionExpressionrepresenting the Euclidean distance. -
Default implementationeuclideanDistance(_:)
Calculates the Euclidean distance between this vector expression and another vector literal (
VectorValue). Assumesselfevaluates to a Vector.let targetPoint = VectorValue(vector: [1.0, 2.0]) Field("currentLocation").euclideanDistance(targetPoint)Default Implementation
Declaration
Swift
func euclideanDistance(_ vector: VectorValue) -> FunctionExpressionParameters
vectorThe other vector as a
VectorValueto compare against.Return Value
A new
FunctionExpressionrepresenting the Euclidean distance. -
Default implementationeuclideanDistance(_:)
Calculates the Euclidean distance between this vector expression and another vector literal (
[Double]). Assumesselfevaluates to a Vector.// Euclidean distance between "location" field and a target location literal Field("location").euclideanDistance([37.7749, -122.4194])Default Implementation
Declaration
Swift
func euclideanDistance(_ vector: [Double]) -> FunctionExpressionParameters
vectorThe other vector as
[Double]to compare against.Return Value
A new
FunctionExpressionrepresenting the Euclidean distance.
-
Default implementationunixMicrosToTimestamp()
Creates an expression that interprets this expression (evaluating to a number) as microseconds since the Unix epoch and returns a timestamp. Assumes
selfevaluates to a number.// Interpret "microseconds" field as microseconds since epoch. Field("microseconds").unixMicrosToTimestamp()Default Implementation
Declaration
Swift
func unixMicrosToTimestamp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the timestamp. -
Default implementationtimestampToUnixMicros()
Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch. Assumes
selfevaluates to a Timestamp.// Convert "timestamp" field to microseconds since epoch. Field("timestamp").timestampToUnixMicros()Default Implementation
Declaration
Swift
func timestampToUnixMicros() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the number of microseconds. -
Default implementationunixMillisToTimestamp()
Creates an expression that interprets this expression (evaluating to a number) as milliseconds since the Unix epoch and returns a timestamp. Assumes
selfevaluates to a number.// Interpret "milliseconds" field as milliseconds since epoch. Field("milliseconds").unixMillisToTimestamp()Default Implementation
Declaration
Swift
func unixMillisToTimestamp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the timestamp. -
Default implementationtimestampToUnixMillis()
Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch. Assumes
selfevaluates to a Timestamp.// Convert "timestamp" field to milliseconds since epoch. Field("timestamp").timestampToUnixMillis()Default Implementation
Declaration
Swift
func timestampToUnixMillis() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the number of milliseconds. -
Default implementationunixSecondsToTimestamp()
Creates an expression that interprets this expression (evaluating to a number) as seconds since the Unix epoch and returns a timestamp. Assumes
selfevaluates to a number.// Interpret "seconds" field as seconds since epoch. Field("seconds").unixSecondsToTimestamp()Default Implementation
Declaration
Swift
func unixSecondsToTimestamp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the timestamp. -
Default implementationtimestampToUnixSeconds()
Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch. Assumes
selfevaluates to a Timestamp.// Convert "timestamp" field to seconds since epoch. Field("timestamp").timestampToUnixSeconds()Default Implementation
Declaration
Swift
func timestampToUnixSeconds() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the number of seconds. -
Default implementationtimestampTruncate(granularity:)
Creates an expression that truncates a timestamp to a specified granularity. Assumes
selfevaluates to a Timestamp.// Truncate "timestamp" field to the nearest day. Field("timestamp").timestampTruncate(granularity: .day)Default Implementation
Declaration
Swift
func timestampTruncate(granularity: TimeGranularity) -> FunctionExpressionParameters
granularityA
TimeGranularityrepresenting the truncation unit.Return Value
A new
FunctionExpressionrepresenting the truncated timestamp. -
Default implementationtimestampTruncate(granularity:)
Creates an expression that truncates a timestamp to a specified granularity. Assumes
selfevaluates to a Timestamp.// Truncate "timestamp" field to the nearest day using a literal string. Field("timestamp").timestampTruncate(granularity: "day") // Truncate "timestamp" field to the nearest day using an expression. Field("timestamp").timestampTruncate(granularity: Field("granularity_field"))Default Implementation
Declaration
Swift
func timestampTruncate(granularity: Sendable) -> FunctionExpressionParameters
granularityA
Sendableliteral string or anExpressionthat evaluates to a string, specifying the truncation unit.Return Value
A new
FunctionExpressionrepresenting the truncated timestamp. -
Default implementationtimestampTruncate(granularity:timezone:)
Creates an expression that truncates a timestamp to a specified granularity with a specified timezone. Assumes
selfevaluates to a Timestamp.// Truncate "timestamp" field to the nearest day in Los Angeles timezone. Field("timestamp").timestampTruncate(granularity: .day, timezone: "America/Los_Angeles")Default Implementation
Declaration
Swift
func timestampTruncate(granularity: TimeGranularity, timezone: Sendable) -> FunctionExpressionParameters
granularityA
TimeGranularityrepresenting the truncation unit.timezoneA
Sendableliteral string or anExpressionrepresenting the timezone.Return Value
A new
FunctionExpressionrepresenting the truncated timestamp. -
Default implementationtimestampTruncate(granularity:timezone:)
Creates an expression that truncates a timestamp to a specified granularity with a specified timezone. Assumes
selfevaluates to a Timestamp.// Truncate "timestamp" field to the nearest day in Los Angeles timezone using a literal // string. Field("timestamp").timestampTruncate(granularity: "day", timezone: "America/Los_Angeles")// Truncate "timestamp" field to the granularity specified by "granularity_field" in the // timezone specified by "timezone_field" using expressions. Field("timestamp").timestampTruncate( granularity: Field("granularity_field"), timezone: Field("timezone_field") )Default Implementation
Declaration
Swift
func timestampTruncate(granularity: Sendable, timezone: Sendable) -> FunctionExpressionParameters
granularityA
Sendableliteral string or anExpressionrepresenting the truncation unit.timezoneA
Sendableliteral string or anExpressionrepresenting the timezone.Return Value
A new
FunctionExpressionrepresenting the truncated timestamp. -
Default implementationtimestampDiff(_:_:)
Calculates the difference between this timestamp and another timestamp.
// Calculate the difference in days between "endAt" (self) and a start field using a typed // unit. Field("endAt").timestampDiff(Field("startAt"), .day)Default Implementation
Declaration
Swift
func timestampDiff(_ start: Expression, _ unit: TimeUnit) -> FunctionExpressionParameters
startAn
Expressionrepresenting the starting timestamp.unitA
TimeUnitrepresenting the unit of time for the difference.Return Value
A new
FunctionExpressionrepresenting the difference. -
Default implementationtimestampDiff(_:_:)
Calculates the difference between this timestamp and another timestamp.
// Calculate the difference in days between "endAt" (self) and a start field using a string // unit. Field("endAt").timestampDiff(Field("startAt"), "day")Default Implementation
Declaration
Swift
func timestampDiff(_ start: Expression, _ unit: Sendable) -> FunctionExpressionParameters
startAn
Expressionrepresenting the starting timestamp.unitA
Sendableliteral string or anExpressionrepresenting the unit of time.Return Value
A new
FunctionExpressionrepresenting the difference. -
Default implementationtimestampExtract(part:)
Creates an expression that extracts a specified part from this timestamp expression.
// Extract the day from the "timestamp" field. Field("timestamp").timestampExtract(part: .day)Default Implementation
Declaration
Swift
func timestampExtract(part: TimePart) -> FunctionExpressionParameters
partA
TimePartrepresenting the part to extract.Return Value
A new
FunctionExpressionrepresenting the extracted part. -
Default implementationtimestampExtract(part:)
Creates an expression that extracts a specified part from this timestamp expression using a literal or expression.
// Extract the day from the "timestamp" field using a string. Field("timestamp").timestampExtract(part: "day")Default Implementation
Declaration
Swift
func timestampExtract(part: Sendable) -> FunctionExpressionParameters
partA
Sendableliteral string or anExpressionrepresenting the part to extract.Return Value
A new
FunctionExpressionrepresenting the extracted part. -
Default implementationtimestampExtract(part:timezone:)
Creates an expression that extracts a specified part from this timestamp expression in a given timezone.
// Extract the day from the "timestamp" field in Los Angeles timezone. Field("timestamp").timestampExtract(part: .day, timezone: "America/Los_Angeles")Default Implementation
Declaration
Swift
func timestampExtract(part: TimePart, timezone: Sendable) -> FunctionExpressionParameters
partA
TimePartrepresenting the part to extract.timezoneA
Sendableliteral string or anExpressionrepresenting the timezone.Return Value
A new
FunctionExpressionrepresenting the extracted part. -
Default implementationtimestampExtract(part:timezone:)
Creates an expression that extracts a specified part from this timestamp expression in a given timezone using a literal or expression.
// Extract the day from the "timestamp" field in Los Angeles timezone using a string. Field("timestamp").timestampExtract(part: "day", timezone: "America/Los_Angeles")Default Implementation
Declaration
Swift
func timestampExtract(part: Sendable, timezone: Sendable) -> FunctionExpressionParameters
partA
Sendableliteral string or anExpressionrepresenting the part to extract.timezoneA
Sendableliteral string or anExpressionrepresenting the timezone.Return Value
A new
FunctionExpressionrepresenting the extracted part. -
Default implementationtimestampAdd(_:_:)
Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as literals. Assumes
selfevaluates to a Timestamp.// Add 1 day to the "timestamp" field. Field("timestamp").timestampAdd(1, .day)Default Implementation
Declaration
Swift
func timestampAdd(_ amount: Int, _ unit: TimeUnit) -> FunctionExpressionParameters
unitThe
TimeUnitenum representing the unit of time.amountThe literal
Intamount of the unit to add.Return Value
A new "FunctionExpression" representing the resulting timestamp.
-
Default implementationtimestampAdd(amount:unit:)
Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as an expression for amount and a literal for unit. Assumes
selfevaluates to a Timestamp,amountevaluates to an integer, andunitevaluates to a string.// Add duration from "amountField" to "timestamp" with a literal unit "day". Field("timestamp").timestampAdd(amount: Field("amountField"), unit: "day")Default Implementation
Declaration
Swift
func timestampAdd(amount: Expression, unit: Sendable) -> FunctionExpressionParameters
unitA
Sendableliteral string specifying the unit of time. Valid units are "microsecond", "millisecond", "second", "minute", "hour", "day".amountAn
Expressionevaluating to the amount (Int) of the unit to add.Return Value
A new "FunctionExpression" representing the resulting timestamp.
-
Default implementationtimestampSubtract(_:_:)
Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as literals. Assumes
selfevaluates to a Timestamp.// Subtract 1 day from the "timestamp" field. Field("timestamp").timestampSubtract(1, .day)Default Implementation
Declaration
Swift
func timestampSubtract(_ amount: Int, _ unit: TimeUnit) -> FunctionExpressionParameters
unitThe
TimeUnitenum representing the unit of time.amountThe literal
Intamount of the unit to subtract.Return Value
A new "FunctionExpression" representing the resulting timestamp.
-
Default implementationtimestampSubtract(amount:unit:)
Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as an expression for amount and a literal for unit. Assumes
selfevaluates to a Timestamp,amountevaluates to an integer, andunitevaluates to a string.// Subtract duration from "amountField" from "timestamp" with a literal unit "day". Field("timestamp").timestampSubtract(amount: Field("amountField"), unit: "day")Default Implementation
Declaration
Swift
func timestampSubtract(amount: Expression, unit: Sendable) -> FunctionExpressionParameters
unitA
Sendableliteral string specifying the unit of time. Valid units are "microsecond", "millisecond", "second", "minute", "hour", "day".amountAn
Expressionevaluating to the amount (Int) of the unit to subtract.Return Value
A new "FunctionExpression" representing the resulting timestamp.
-
Default implementationdocumentId()
Creates an expression that returns the document ID from a path.
// Get the document ID from a path. Field(FieldPath.documentID()).documentId()Default Implementation
Declaration
Swift
func documentId() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the documentId operation. -
Default implementationcollectionId()
Gets the collection id (kind) of a given document (either an absolute or namespace relative reference). Throw error if the input is the root itself.
Default Implementation
Declaration
Swift
func collectionId() -> FunctionExpression -
Default implementationparent()
Creates an expression that returns the parent document reference of a document reference.
// Get the parent document reference of a document reference. Field("__path__").parent()Default Implementation
Declaration
Swift
func parent() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the parent operation. -
Default implementationifError(_:)
Creates an expression that returns the result of
catchExpressionif this expression produces an error during evaluation, otherwise returns the result of this expression.// Try dividing "a" by "b", return field "fallbackValue" on error (e.g., division by zero) Field("a").divide(Field("b")).ifError(Field("fallbackValue"))Default Implementation
Declaration
Swift
func ifError(_ catchExpression: Expression) -> FunctionExpressionParameters
catchExpressionThe
Expressionto evaluate and return if this expression errors.Return Value
A new "FunctionExpression" representing the "ifError" operation.
-
Default implementationifError(_:)
Creates an expression that returns the literal
catchValueif this expression produces an error during evaluation, otherwise returns the result of this expression.// Get first item in "title" array, or return "Default Title" if error (e.g., empty array) Field("title").arrayGet(0).ifError("Default Title")Default Implementation
Declaration
Swift
func ifError(_ catchValue: Sendable) -> FunctionExpressionParameters
catchValueThe literal
Sendablevalue to return if this expression errors.Return Value
A new "FunctionExpression" representing the "ifError" operation.
-
Default implementationifAbsent(_:)
Creates an expression that returns the literal
defaultValueif this expression is absent (e.g., a field does not exist in a map). Otherwise, returns the result of this expression.// If the "optionalField" is absent, return "default value". Field("optionalField").ifAbsent("default value")Default Implementation
Declaration
Swift
func ifAbsent(_ defaultValue: Sendable) -> FunctionExpressionParameters
defaultValueThe literal
Sendablevalue to return if this expression is absent.Return Value
A new "FunctionExpression" representing the "ifAbsent" operation.
-
Default implementationifNull(_:)
Creates an expression that returns the
elseargument if this expression evaluates to null, else return the result of this expression.This function provides a fallback for both absent and explicit null values. In contrast,
ifAbsentonly triggers for missing fields.// Returns the user's display name, or returns "Anonymous" if the field is null. Field("displayName").ifNull("Anonymous")Default Implementation
Declaration
Swift
func ifNull(_ defaultValue: Sendable) -> FunctionExpressionParameters
defaultValueThe
Sendablevalue that will be returned if this expression evaluates to null.Return Value
A new
FunctionExpressionrepresenting theifNulloperation. -
Default implementationifNull(_:)
Creates an expression that returns the
elseargument if this expression evaluates to null, else return the result of this expression.This function provides a fallback for both absent and explicit null values. In contrast,
ifAbsentonly triggers for missing fields.// Returns the user's preferred name, or if that is null, returns their full name. Field("preferredName").ifNull(Field("fullName"))Default Implementation
Declaration
Swift
func ifNull(_ defaultExpression: Expression) -> FunctionExpressionParameters
defaultExpressionThe
Expressionthat will be evaluated and returned if this expression evaluates to null.Return Value
A new
FunctionExpressionrepresenting theifNulloperation. -
Default implementationcoalesce(_:)
Creates an expression that returns the first non-null, non-absent argument, without evaluating the rest of the arguments. When all arguments are null or absent, returns the last argument.
// Returns the value of the first non-null, non-absent field among 'preferredName', 'fullName', or the last argument if all previous fields are null. Field("preferredName").coalesce([Field("fullName"), Constant("Anonymous")])Default Implementation
Declaration
Swift
func coalesce(_ values: [Expression]) -> FunctionExpressionParameters
valuesOptional additional expressions to check if previous ones are null.
Return Value
A new
FunctionExpressionrepresenting thecoalesceoperation.
-
Default implementationascending()
Creates an
Orderingobject that sorts documents in ascending order based on this expression.// Sort documents by the "name" field in ascending order firestore.pipeline().collection("users") .sort(Field("name").ascending())Default Implementation
Declaration
Swift
func ascending() -> OrderingReturn Value
A new
Orderinginstance for ascending sorting. -
Default implementationdescending()
Creates an
Orderingobject that sorts documents in descending order based on this expression.// Sort documents by the "createdAt" field in descending order firestore.pipeline().collection("users") .sort(Field("createdAt").descending())Default Implementation
Declaration
Swift
func descending() -> OrderingReturn Value
A new
Orderinginstance for descending sorting. -
Default implementationconcat(_:)
Creates an expression that concatenates multiple sequenceable types together.
// Concatenate the firstName and lastName with a space in between. Field("firstName").concat([" ", Field("lastName")])Default Implementation
Declaration
Swift
func concat(_ values: [Sendable]) -> FunctionExpressionParameters
valuesThe values to concatenate.
Return Value
A new
FunctionExpressionrepresenting the concatenated result. -
Default implementationtype()
Creates an expression that returns the type of the expression.
// Get the type of the "rating" field. Field("rating").type()Default Implementation
Declaration
Swift
func type() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the type of the expression as a string. -
Default implementationisType(_:)
Creates an expression that checks if the result of this expression is of the given type.
Supported values for
typeare:"null","array","boolean","bytes","timestamp","geo_point","number","int32","int64","float64","decimal128","map","reference","string","vector","max_key","min_key","object_id","regex", and"request_timestamp".// Check if the "age" field is an integer Field("age").isType("int64")Default Implementation
Declaration
Swift
func isType(_ type: String) -> BooleanExpressionParameters
typeThe type to check for.
Return Value
A new
BooleanExpressionthat evaluates to true if the expression's result is of the given type, false otherwise.
-
Extension methodsnippet(_:maxSnippetWidth:maxSnippets:separator:)
Undocumented
Declaration
Swift
func snippet(_ rquery: String, maxSnippetWidth: Int? = nil, maxSnippets: Int? = nil, separator: String? = nil) -> Expression
-
Extension methodbetween(_:_:)
Undocumented
Declaration
Swift
func between(_ lowerBound: Sendable, _ upperBound: Sendable) -> BooleanExpression -
Extension methodbetween(_:_:)
Undocumented
Declaration
Swift
func between(_ lowerBound: Expression, _ upperBound: Expression) -> BooleanExpression