shape-runtime 0.3.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`.
    method findIndex(predicate: (T) => bool) -> int;
    /// Return whether the collection contains `value`.
    method includes(value: T) -> bool;
    /// Pair each element with the corresponding element from `other`.
    method zip(other) -> Self;
    /// Split the collection into fixed-size chunks.
    method chunk(size: int) -> Array<Array<T>>;
    /// Remove duplicate values while preserving order.
    method unique() -> Self;
    /// Flatten one level of nested iterables.
    method flatten() -> Self;
    /// Return the slice in `[start, end)`.
    method slice(start: int, end: int) -> Self;
    /// Join elements into a string with `separator`.
    method join(separator: string) -> string;
    /// Return a new collection sorted by `key_fn`.
    method sortBy(key_fn: (T) => number) -> Self;
    /// Return the first `n` elements.
    method take(n: int) -> Self;
    /// Skip the first `n` elements.
    method skip(n: int) -> Self;
    /// Pair each element with its index.
    method enumerate() -> Array<[int, T]>;
}