Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Check if List Contains Element
Determine if an item exists within a list using the natural contains 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 Core Language Spec (D13)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
if ${items} contains ${targetItem}
say "Item found in list"
.
allowedRoles are
"admin"
"moderator"
.
userRole is "admin"
guestRole is "guest"
hasAdmin is false
if allowedRoles contains userRole
hasAdmin is true
.
hasGuest is false
if allowedRoles contains guestRole
hasGuest is true
.
say "Has admin:" hasAdmin
say "Has guest:" hasGuest
if hasAdmin is not true
fail with "list-contains expected admin to be present"
.
if hasGuest is not false
fail with "list-contains expected guest to be absent"
.
Installation & Usage
otter snippet inspect list-contains-check
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.