Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iter): tap #1371

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/builtin.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Iter {
singleton[T](T) -> Self[T]
take[T](Self[T], Int) -> Self[T]
take_while[T](Self[T], (T) -> Bool) -> Self[T]
tap[T](Self[T], (T) -> Unit) -> Self[T] //deprecated
tap[T](Self[T], (T) -> Unit) -> Self[T]
to_array[T](Self[T]) -> Array[T]
}
impl[T : Show] Show for Iter[T]
Expand Down
11 changes: 6 additions & 5 deletions builtin/iter.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,13 @@ pub fn flat_map[T, R](self : Iter[T], f : (T) -> Iter[R]) -> Iter[R] {
/// # Returns
///
/// The same iterator.
///
/// @alert deprecated "use cascade operator [..] instead"
/// @coverage.skip
pub fn tap[T](self : Iter[T], f : (T) -> Unit) -> Iter[T] {
self.each(f)
self
self.map(fn {
a => {
f(a)
a
}
})
}

///|
Expand Down
4 changes: 2 additions & 2 deletions builtin/iter_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ test "find_first2" {
test "tap" {
let iter = test_from_array(['1', '2', '3', '4', '5'])
let exb = StringBuilder::new(size_hint=0)
iter..each(fn { x => exb.write_char(x) }).each(fn { x => exb.write_char(x) })
inspect!(exb, content="1234512345")
iter.tap(fn { x => exb.write_char(x) }).each(fn { x => exb.write_char(x) })
inspect!(exb, content="1122334455")
}

test "prepend" {
Expand Down
Loading