Xano Documentation
  • 👋Welcome to Xano!
  • 🌟Frequently Asked Questions
  • 🔐Security & Compliance (Trust Center)
  • 🙏Feature Requests
  • 💔Known Issues
  • Before You Begin
    • Using These Docs
    • Where should I start?
    • Set Up a Free Xano Account
    • Key Concepts
    • The Development Life Cycle
    • Navigating Xano
    • Plans & Pricing
  • The Database
    • Designing your Database
    • Database Basics
      • Using the Xano Database
      • Field Types
      • Relationships
      • Database Views
      • Export and Sharing
      • Data Sources
    • Migrating your Data
      • Airtable to Xano
      • Supabase to Xano
      • CSV Import & Export
    • Database Performance and Maintenance
      • Storage
      • Indexing
      • Maintenance
      • Schema Versioning
  • 🛠️The Function Stack
    • Building with Visual Development
      • APIs
        • Swagger (OpenAPI Documentation)
      • Custom Functions
        • Async Functions
      • Background Tasks
      • Triggers
      • Middleware
      • Configuring Expressions
      • Working with Data
    • Functions
      • AI Tools
      • Database Requests
        • Query All Records
          • External Filtering Examples
        • Get Record
        • Add Record
        • Edit Record
        • Add or Edit Record
        • Patch Record
        • Delete Record
        • Bulk Operations
        • Database Transaction
        • External Database Query
        • Direct Database Query
        • Get Database Schema
      • Data Manipulation
        • Create Variable
        • Update Variable
        • Conditional
        • Switch
        • Loops
        • Math
        • Arrays
        • Objects
        • Text
      • Security
      • APIs & Lambdas
        • Realtime Functions
        • External API Request
        • Lambda Functions
      • Data Caching (Redis)
      • Custom Functions
      • Utility Functions
      • File Storage
      • Cloud Services
    • Filters
      • Manipulation
      • Math
      • Timestamp
      • Text
      • Array
      • Transform
      • Conversion
      • Comparison
      • Security
    • Data Types
      • Text
      • Expression
      • Array
      • Object
      • Integer
      • Decimal
      • Boolean
      • Timestamp
      • Null
    • Environment Variables
    • Additional Features
      • Response Caching
  • Testing and Debugging
    • Testing and Debugging Function Stacks
    • Unit Tests
    • Test Suites
  • CI/CD
  • File Storage
    • File Storage in Xano
    • Private File Storage
  • Realtime
    • Realtime in Xano
    • Channel Permissions
    • Realtime in Webflow
  • Maintenance, Monitoring, and Logging
    • Statement Explorer
    • Request History
    • Instance Dashboard
      • Memory Usage
  • Building Backend Features
    • User Authentication & User Data
      • Separating User Data
      • Restricting Access (RBAC)
      • OAuth (SSO)
    • Webhooks
    • Messaging
    • Emails
    • Custom Report Generation
    • Fuzzy Search
    • Chatbots
  • Xano Features
    • Snippets
    • Instance Settings
      • Release Track Preferences
      • Static IP (Outgoing)
      • Change Server Region
      • Direct Database Connector
      • Backup and Restore
      • Security Policy
    • Workspace Settings
    • Advanced Back-end Features
      • Xano Link
      • Developer API (Deprecated)
    • Metadata API
      • Master Metadata API
      • Tables and Schema
      • Content
      • Search
      • File
      • Request History
      • Workspace Import and Export
      • Token Scopes Reference
  • Build With AI
    • Building a Backend Using AI
    • Get Started Assistant
    • AI Database Assistant
    • AI Lambda Assistant
    • AI SQL Assistant
    • API Request Assistant
    • Template Engine
    • Streaming APIs
  • Using AI Builders with Xano
  • Build For AI
    • MCP Builder
      • Connecting Clients
      • MCP Functions
    • Xano MCP Server
  • Xano Transform
    • Using Xano Transform
  • Xano Actions
    • What are Actions?
    • Browse Actions
  • Team Collaboration
    • Realtime Collaboration
    • Managing Team Members
    • Branching & Merging
    • Role-based Access Control (RBAC)
  • Agencies
    • Xano for Agencies
    • Agency Features
      • Agency Dashboard
      • Client Invite
      • Transfer Ownership
      • Agency Profile
      • Commission
      • Private Marketplace
  • Enterprise
    • Xano for Enterprise
    • Enterprise Features
      • Microservices
        • Ollama
          • Choosing a Model
      • Tenant Center
      • Compliance Center
      • Security Policy
      • Instance Activity
      • Deployment
      • RBAC (Role-based Access Control)
      • Xano Link
  • Your Xano Account
    • Account Page
    • Billing
    • Referrals & Commissions
  • Troubleshooting & Support
    • Error Reference
    • Troubleshooting Performance
      • When a single workflow feels slow
      • When everything feels slow
      • RAM Usage
      • Function Stack Performance
    • Getting Help
      • Granting Access
      • Community Code of Conduct
      • Community Content Modification Policy
  • Special Pricing
    • Students & Education
    • Non-Profits
  • Security
    • Best Practices
Powered by GitBook
On this page
  • Lambda Filters
  • map
  • some
  • every
  • find
  • findIndex
  • filter
  • reduce

Was this helpful?

  1. The Function Stack
  2. Filters

Transform

Last updated 5 months ago

Was this helpful?

Lambda Filters

Higher Order Filters operate on a list of items and process a Lambda individually for each item. The Lambda has access to several context variables that represent various states of the iteration process. Details of each of these context variables are mentioned below.

map

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed

  • $parent - the context variable that represents the entire array with all of its elements.

The map filter is extremely powerful because it allows you to easily transform the elements of one array into another. Here is an example of using using a map on a variable that contains a list of user objects. We will convert that into a list of user usernames.

return $this.username;

The above example changes the type of the array. Previously it was an array of user objects, but now it is an array of text. You can also use the map filter to return a subject each object while still maintaining the object type.

return {id: $this.id, username: $this.username};

some

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed.

  • $parent - the context variable that represents the entire array with all of its elements.

The some filter (also called has or has any element) allows you to easily determine if there is at least one element of an array that matches your condition. A common use case would be having an array of role objects and you wanted to see if a certain role was present.

return $this.role == "admin";

every

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed.

  • $parent - the context variable that represents the entire array with all of its elements.

This filter (also called find every element) is identical to the some filter except that it requires that all elements of the array match the condition. A common use case would be a list of products and determining if they all have a price greater than 10.

return $this.price > 10;

find

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed.

  • $parent - the context variable that represents the entire array with all of its elements.

This filter (also called find first element) is identical to the some filter except that it returns the actual element that matches the condition instead of returning whether or not it was found. A common use case would be finding the first product that has a price greater than 10.

return $this.price > 10;

findIndex

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed.

  • $parent - the context variable that represents the entire array with all of its elements.

This filter (also called find first element index) is identical to the some filter except that it returns the index of the element that matches the condition instead of returning whether or not it was found. A common use case would be finding the index of the first product that has a price greater than 10.

return $this.price > 10;

filter

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed.

  • $parent - the context variable that represents the entire array with all of its elements.

This filter (also called find all elements) is identical to the find filter except that it returns it returns all elements that match the condition. Even if there is only one match, it would return an array of one. A common use case would be finding all products that have a price greater than 10.

return $this.price > 10;

reduce

  • $this - the context variable that represents the element of the array being processed.

  • $index - the context variable that represents the numerical index of the element of the array being processed.

  • $parent - the context variable that represents the entire array with all of its elements.

  • $result - the context variable that is used to represent the result of the previous iteration or the initial value on the first iteration.

This reduce filter is a bit more complicated than the higher order examples because its environment changes each time the Lambda is processed. The reduce filter starts out with an initial value (normally 0) and then is responsible for turning the array into a single result. Because of this, there is a new context variable named $result which can be referenced. The $result variable is the state of the reduction process. The first time the Lambda runs, the $result variable is the same as the initial variable. The return statement of the Lambda will be the $result variable for the 2nd iteration and so forth until there are no iterations left. The final value of the $result variable will be assigned to whatever is referencing the reduce filter.

The details above may feel like a mouthful, but things should start to click when seeing a few examples.

The most basic example would be sum a list of values.

Using an initial value of 0 we would get the sum of numbers with the following Lambda.

return $this + $result;

If the above example was a list of objects instead of a list of scalar values, then the Lambda would change slightly.

return $this.num + $result;

🛠️
List of user objects.
Map filter used to transform the list of user objects
The result is the list of usernames.
List of user objects.
This will generate a true value if a role of admin is found in the array and a false value if it is not.
In this example, Every filter will determine if every price in the products array is greater than 10.
In this example, the first product object with a price greater than 10 will be returned.
In this example, findIndex will return the first element index where the price is greater than 10.
In this example, filter will return all elements where the price is greater than 10.
Here's an example array of [1, 10, 100].
In this example, the reduce filter will result in a sum of the array or 111.
In this example, we have an array of objects.
Using the reduce filter in this example, we sum the values of num for each object resulting in 111.