Skip to content

Commit

Permalink
update doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FlammeShadow authored and bobzhang committed Dec 15, 2024
1 parent 2644019 commit 9f8c715
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion array/view.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,35 @@ pub fn each[T](self : ArrayView[T], f : (T) -> Unit) -> Unit {
}

///|
/// Iterates over the elements of the array view with index.
///
/// # Example
///
/// ```
/// let v = [3, 4, 5][:]
/// let mut sum = 0
/// v.eachi(fn (i, x) { sum = sum + x + i })
/// assert_eq!(sum, 15)
/// ```
pub fn eachi[T](self : ArrayView[T], f : (Int, T) -> Unit) -> Unit {
for i, v in self {
f(i, v)
}
}

///|
/// Checks if all elements in the array view match the condition.
///
/// # Example
///
/// ```
/// let v = [1, 4, 6, 8, 9]
/// assert_false!(v[:].all(fn(elem) { elem % 2 == 0 }))
/// assert_true!(v[1:4].all(fn(elem) { elem % 2 == 0 }))
/// ```
pub fn all[T](self : ArrayView[T], f : (T) -> Bool) -> Bool {
for v in self {
if f(v).not() {
if not(f(v)) {
return false
}
}
Expand Down

0 comments on commit 9f8c715

Please sign in to comment.