simple_container logo

simple_container

Functional-style collection operations with composable query conditions

MIT License Eiffel 25.02 Design by Contract

Overview

simple_container provides functional-style operations for Eiffel collections without cursor manipulation headaches. Instead of manually managing cursors with start, forth, and after, you use composable query conditions and declarative operations like filtered, take, drop, and partition.

The library introduces a boolean algebra of query conditions where you can combine predicates using and, or, and not operators.

Quick Start

local
    l_list: ARRAYED_LIST [INTEGER]
    l_query: SIMPLE_LIST_QUERY [INTEGER]
    l_cond: SIMPLE_PREDICATE_CONDITION [INTEGER]
    l_result: ARRAYED_LIST [INTEGER]
do
    create l_list.make_from_array (<<1, 2, 3, 4, 5, 6, 7, 8, 9, 10>>)
    create l_query.make (l_list)
    create l_cond.make (agent (i: INTEGER): BOOLEAN do Result := i > 5 end)
    l_result := l_query.filtered (l_cond)
    -- l_result contains: 6, 7, 8, 9, 10
end

API Reference

SIMPLE_QUERY_CONDITION [G]

Abstract base for composable boolean conditions.

FeatureDescription
satisfied_by (a_item)Check if item satisfies condition
conjuncted alias "and"Combine with AND
disjuncted alias "or"Combine with OR
negated alias "not"Negate condition

SIMPLE_LIST_QUERY [G]

Cursor-safe query operations on lists.

FeatureDescription
filtered (a_condition)Items satisfying condition
first_satisfying (a_condition)First matching item or Void
all_satisfy (a_condition)Do all items satisfy?
any_satisfies (a_condition)Does any item satisfy?
count_satisfying (a_condition)Count of matching items
mapped (a_function)Apply function to each item
folded (a_initial, a_combiner)Reduce to single value

SIMPLE_LIST_EXTENSIONS [G]

Extension operations for lists.

FeatureDescription
partition (a_condition)Split into satisfying/not satisfying
group_by (a_key_function)Group by key
min_by (a_selector)Element with minimum selector value
max_by (a_selector)Element with maximum selector value
index_of_first (a_condition)Index of first matching element
index_of_last (a_condition)Index of last matching element
reversedItems in reverse order
take (n)First n items
drop (n)All except first n items
zip (a_other)Combine lists element-by-element
chunked (a_size)Split into fixed-size sublists
windowed (a_size)Sliding window sublists

SIMPLE_SORTABLE_LIST_EXTENSIONS [G]

Sorting operations for lists.

FeatureDescription
sorted_by (a_key)Elements sorted by key (ascending)
sorted_by_descending (a_key)Elements sorted by key (descending)

SIMPLE_HASHABLE_LIST_EXTENSIONS [G -> HASHABLE]

Distinct operations for hashable lists.

FeatureDescription
distinctElements with duplicates removed
distinct_by (a_key)Elements with duplicates by key removed

SIMPLE_SLICE [G]

Lazy slice view into arrays/lists (no copying).

FeatureDescription
make (a_source, a_start, a_end)Create slice from range
item alias "[]" (i)Item at position
to_array / to_listConvert to concrete container
sub_sliceCreate sub-slice

SIMPLE_SET_OPERATIONS [G -> HASHABLE]

Set operations on collections.

FeatureDescription
unionAll items in either collection
intersectionItems in both collections
differenceItems in first but not second
is_subsetCheck if subset

Features

Installation

Add to your .ecf file:

<library name="simple_container" location="$SIMPLE_LIBS/simple_container/simple_container.ecf"/>