Skip to content

Commit

Permalink
feat(builtin): add Iter2::concat()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Feb 7, 2025
1 parent 0ac3614 commit 555630c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions builtin/iter2.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,35 @@ pub fn Iter2::to_array[A, B](self : Iter2[A, B]) -> Array[(A, B)] {
}
arr
}

///|
/// Combines two iterators into one by appending the elements of the second iterator to the first.
///
/// # Arguments
///
/// * `self` - The first input iterator.
/// * `other` - The second input iterator to be appended to the first.
///
/// # Returns
///
/// Returns a new iterator that contains the elements of `self` followed by the elements of `other`.
///
/// # Examples
///
/// ```moonbit
/// test "Iter2::concat" {
/// inspect!(
/// "abcde".iter2().concat("fghij".iter2()).to_array(),
/// content="[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (0, 'f'), (1, 'g'), (2, 'h'), (3, 'i'), (4, 'j')]",
/// )
/// }
/// ```
pub fn Iter2::concat[A, B](
self : Iter2[A, B],
other : Iter2[A, B]
) -> Iter2[A, B] {
fn(yield_) {
guard self.run(yield_) == IterContinue else { IterEnd }
other.run(yield_)
}
}

0 comments on commit 555630c

Please sign in to comment.