Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Filter List by Condition
Filter elements from a list into a new target list using a condition.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Collections & Lists). Copy the parameterized template or run the self-contained example.
- 1Category: Collections & Lists
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
filtered are empty
for each ${item} in ${items}
if ${condition}
add ${item} to filtered
.
.
numbers are
12
5
28
3
45
.
highNumbers are empty
for each n in numbers
if n is at least 10
add n to highNumbers
.
.
say "Found numbers >= 10:" length of highNumbers
if length of highNumbers is not 3
fail with "filter count mismatch: expected 3 items"
.
if not highNumbers contains 28
fail with "filtered list missing element 28"
.
Installation & Usage
otter snippet inspect list-filter-items
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.