shape-runtime 0.2.0

Bytecode compiler, builtins, and runtime infrastructure for Shape
Documentation
/// @module std::core::iterable
/// Iterable trait — uniform iteration interface for ordered collections.
///
/// Any type that implements Iterable gets access to a rich set of
/// collection operations: slicing, searching, deduplication, chunking, etc.
///
/// Queryable stays lean (filter/map/orderBy/limit/execute) for database queries.
/// Iterable is for in-memory, ordered collections (Array, Table).
///
/// ## Known Implementations
///
/// | Type   | Location                                    | Status   |
/// |--------|---------------------------------------------|----------|
/// | Array  | stdlib/core/array_iterable.shape             | Verified |
/// | Table  | stdlib/core/table_iterable.shape             | Verified |

/// Uniform iteration interface for ordered in-memory collections.
///
/// `Iterable` powers collection-style operations on arrays and tables without
/// constraining backends to the query-planning semantics of
/// `std::core::queryable::Queryable`.
///
/// @see std::core::queryable::Queryable
trait Iterable<T> {
    /// Return the index of the first element that satisfies `predicate`.
    findIndex(predicate: (T) => bool): int,
    /// Return whether the collection contains `value`.
    includes(value: T): bool,
    /// Pair each element with the corresponding element from `other`.
    zip(other): Self,
    /// Split the collection into fixed-size chunks.
    chunk(size: int): Array<Array<T>>,
    /// Remove duplicate values while preserving order.
    unique(): Self,
    /// Flatten one level of nested iterables.
    flatten(): Self,
    /// Return the slice in `[start, end)`.
    slice(start: int, end: int): Self,
    /// Join elements into a string with `separator`.
    join(separator: string): string,
    /// Return a new collection sorted by `key_fn`.
    sortBy(key_fn: (T) => number): Self,
    /// Return the first `n` elements.
    take(n: int): Self,
    /// Skip the first `n` elements.
    skip(n: int): Self,
    /// Pair each element with its index.
    enumerate(): Array<[int, T]>
}