Key Facts
- Category
- Data Processing
- Input Types
- textarea, select, text
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
The Take While tool allows you to extract a prefix from an array by selecting elements from the beginning until a specified condition is no longer met.
When to Use
- •When you need to truncate a list of data as soon as a specific value threshold is reached.
- •When filtering log entries or time-series data to capture only the initial sequence that satisfies a condition.
- •When cleaning datasets by removing trailing elements that fall outside of your required criteria.
How It Works
- •Input your data as a standard JSON array.
- •Select a predicate type from the list, such as 'less than' or 'string starts with'.
- •Provide a comparison value to define the boundary for the extraction.
- •The tool processes the array using lodash _.takeWhile and returns the matching prefix.
Use Cases
Examples
1. Extracting Low-Value Transactions
- Background
- A financial analyst has a list of transaction amounts and needs to identify the initial streak of small purchases before a large transaction occurs.
- Problem
- Manually identifying the cutoff point in a long list of numbers is prone to error.
- How to Use
- Input the transaction array, select 'Less than', and set the compare value to 100.
- Example Config
-
Array: [20, 45, 80, 150, 30], Predicate: Less than, Compare Value: 100 - Outcome
- Returns [20, 45, 80], stopping at 150.
2. Filtering Log Prefixes
- Background
- A developer needs to extract all log messages that start with a specific status code prefix before the system encountered an error.
- Problem
- Need to isolate the healthy startup sequence from a log array.
- How to Use
- Input the log array, select 'String starts with', and set the compare value to 'INFO'.
- Example Config
-
Array: ['INFO: start', 'INFO: init', 'ERROR: fail', 'INFO: retry'], Predicate: String starts with, Compare Value: INFO - Outcome
- Returns ['INFO: start', 'INFO: init'], stopping at the first 'ERROR' entry.
Try with Samples
jsonRelated Hubs
FAQ
What happens if the first element does not match the predicate?
The tool will return an empty array because the condition is not met at the very start of the sequence.
Does this tool modify the original array?
No, the tool processes the input and returns a new JSON array containing only the matching prefix.
Can I use this for string arrays?
Yes, you can use predicates like 'string starts with' or 'string contains' to filter string-based arrays.
What is the difference between this and a standard filter?
A filter checks every element in the array, whereas Take While stops processing immediately once it encounters an element that fails the condition.
Is the comparison value mandatory?
It is required for most predicates, though some options like 'is truthy' or 'is nullish' do not require an additional comparison value.