Skip to content

Commit

Permalink
Merge pull request #317 from moonbitlang/yuxiang/add-missing-intrinsi…
Browse files Browse the repository at this point in the history
…c-mark

iter: add back missing intrinsic mark
  • Loading branch information
hackwaly authored Apr 23, 2024
2 parents 431458b + 718e7a9 commit aaec555
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iter/operators.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/// # Returns
///
/// A new iterator that only contains the elements for which the predicate function returns `true`.
/// @intrinsic %iter.filter
pub fn filter[T](self : Iter[T], f : (T) -> Bool) -> Iter[T] {
Iter::Iter(
fn { yield => (self.0)(fn { a => if f(a) { yield(a) } else { true } }) },
Expand All @@ -47,6 +48,7 @@ pub fn filter[T](self : Iter[T], f : (T) -> Bool) -> Iter[T] {
/// # Returns
///
/// A new iterator that contains the transformed elements.
/// @intrinsic %iter.map
pub fn map[T, R](self : Iter[T], f : (T) -> R) -> Iter[R] {
Iter::Iter(fn { yield => (self.0)(fn { a => yield(f(a)) }) })
}
Expand All @@ -66,6 +68,7 @@ pub fn map[T, R](self : Iter[T], f : (T) -> R) -> Iter[R] {
/// # Returns
///
/// A new iterator that contains the flattened elements.
/// @intrinsic %iter.flat_map
pub fn flat_map[T, R](self : Iter[T], f : (T) -> Iter[R]) -> Iter[R] {
Iter::Iter(fn { yield => (self.0)(fn { x => (f(x).0)(yield) }) })
}
Expand Down Expand Up @@ -103,6 +106,7 @@ pub fn tap[T](self : Iter[T], f : (T) -> Unit) -> Iter[T] {
/// # Returns
///
/// A new iterator that contains the first `n` elements.
/// @intrinsic %iter.take
pub fn take[T](self : Iter[T], n : Int) -> Iter[T] {
Iter::Iter(
fn {
Expand Down

0 comments on commit aaec555

Please sign in to comment.