Otter Packs Otter Upstream Contract & Behavioral Tests

list-utils Pack

Essential collection and list helpers: hasItem, dedupeList, countMatches, joinWithPrefix, removeItemFromList, findFirstMatch, sortList, reverseList, calcListSum, and sliceList.

ID: otter-official/list-utils Version: 1.0.1 License: MIT Framework: Otter >=1.0.1

Schema v2 Operation Contract (10 operations)

Scoping Prefix: _lu_

Schema v2 Pack exposing 10 structurally AST-verified Otter 1.0.1 operations with isolated prefix '_lu_'.

Operation SignatureReturnsSide EffectsError Mode
hasItem(items: list, target: any) boolean none returns-false
dedupeList(items: list) list none returns-fallback
countMatches(items: list, target: any) number none returns-fallback
joinWithPrefix(items: list, prefix: text) list none returns-fallback
removeItemFromList(items: list, target: any) list none returns-fallback
findFirstMatch(items: list, target: any) any none returns-gone
sortList(items: list) list none returns-fallback
reverseList(items: list) list none returns-fallback
calcListSum(items: list) number none returns-fallback
sliceList(items: list, startIndex: number, countLimit: number) list none returns-fallback

Source Code (4 files)

src/main.ot · otter
# list-utils - Otter Reusable Collection Library
# Provides hasItem, dedupeList, countMatches, joinWithPrefix,
# removeItemFromList, findFirstMatch, sortList, reverseList,
# calcListSum, and sliceList
# Internal variables use '_lu_' prefix to prevent collisions with caller/outer variables.

to hasItem items target
    if items contains target
        return true
    .
    return false
.

to dedupeList items
    _lu_result are empty
    for each _lu_it in items
        if not _lu_result contains _lu_it
            add _lu_it to _lu_result
        .
    .
    return _lu_result
.

to countMatches items target
    _lu_matches is 0
    for each _lu_it in items
        if _lu_it is target
            _lu_matches is _lu_matches plus 1
        .
    .
    return _lu_matches
.

to joinWithPrefix items prefix
    _lu_result are empty
    for each _lu_it in items
        _lu_combined is prefix plus _lu_it
        add _lu_combined to _lu_result
    .
    return _lu_result
.

to removeItemFromList items target
    _lu_result are empty
    for each _lu_it in items
        if _lu_it is not target
            add _lu_it to _lu_result
        .
    .
    return _lu_result
.

to findFirstMatch items target
    for each _lu_it in items
        if _lu_it is target
            return _lu_it
        .
    .
    return gone
.

to sortList items
    _lu_copy are empty
    for each _lu_it in items
        add _lu_it to _lu_copy
    .
    sort _lu_copy
    return _lu_copy
.

to reverseList items
    _lu_copy are empty
    for each _lu_it in items
        add _lu_it to _lu_copy
    .
    reverse _lu_copy
    return _lu_copy
.

to calcListSum items
    _lu_total is 0
    for each _lu_it in items
        _lu_total is _lu_total plus _lu_it
    .
    return _lu_total
.

to sliceList items startIndex countLimit
    _lu_result are empty
    _lu_idx is 1
    _lu_endIdx is startIndex plus countLimit
    for each _lu_it in items
        if _lu_idx is at least startIndex
            if _lu_idx is less than _lu_endIdx
                add _lu_it to _lu_result
            .
        .
        _lu_idx is _lu_idx plus 1
    .
    return _lu_result
.

Installation & Usage

otter pack install otter-official/list-utils
otter pack verify --contracts

use ".otter/packages/otter-official/list-utils/1.0.1/src/main.ot" # Inspect exported operation contracts: otter pack contract otter-official/list-utils