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 1b08068 commit 7054447
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions builtin/iter2.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,37 @@ 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" {
/// let ns = [10, 11, 12, 13, 14]
/// let ms = [15, 16, 17, 18, 19]
/// inspect!(
/// ns.iter2().concat(ms.iter2()).to_array(),
/// content="[(0, 10), (1, 11), (2, 12), (3, 13), (4, 14), (0, 15), (1, 16), (2, 17), (3, 18), (4, 19)]",
/// )
/// }
/// ```
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 7054447

Please sign in to comment.