Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-10-28 22:13:49 -05:00
commit 05756094ac
706 files changed
+135430

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#! @file iterable.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains the iterable trait, which lends an iterator over the elements a
#! container holds, and which a `for` loop walks.
module core;
#! Lends an iterator over the elements it holds, as references to them.
#!
#! `for x in c` calls `iter(&this)` once and walks what it gives, copying each
#! element, and `for &x in c` refers to each instead. `for &mut x in c` calls
#! `iter(&mut this)`, which a container whose elements may be changed in place
#! gives, and which one that only reads leaves out. What `iter` gives is closed
#! where the loop ends, however it ends, where it is `owning`.
#!
#! The iterator types are asked of the container, as `type list<T>::cursor =
#! ...;`, so generic code names them through a bound, as `C::cursor` where `C:
#! iterable<T>`.
#! @tparam T The type of the elements, which the iterators give references to.
pub trait iterable<T> {
#! What `iter(&this)` gives, which gives references that read the elements.
type cursor: iterator<&T>;
#! What `iter(&mut this)` gives, which gives references that write them.
@optional
type mut_cursor: iterator<&mut T>;
#! Lends an iterator that reads the elements.
#! @param this The container to iterate.
#! @returns The iterator, which refers into the container.
def iter(&this): cursor;
#! Lends an iterator that writes the elements where they are.
#! @param this The container to iterate.
#! @returns The iterator, which refers into the container.
@optional
def iter(&mut this): mut_cursor;
}