Skip to content

Commit

Permalink
Stream - microptimise EvalTap
Browse files Browse the repository at this point in the history
Expand the implementation of evalMap inside evalTap.
Instead of making the `as` call in the underlying effect `F`, we can
just use the Pull `>>` sequencing operator, to ignore the result of
running the action.

For binary compatibility we keep an old version without the implicit.

Co-authored-by: Arman Bilge <armanbilge@gmail.com>
  • Loading branch information
diesalbla and armanbilge committed Apr 2, 2023
1 parent 46a98f8 commit f96c01d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,14 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
* Not as powerful as `observe` since not all pipes can be represented by `O => F[O2]`, but much faster.
* Alias for `evalMap(o => f(o).as(o))`.
*/
def evalTap[F2[x] >: F[x]: Functor, O2](f: O => F2[O2]): Stream[F2, O] =
evalMap(o => f(o).as(o))
def evalTap[F2[x] >: F[x], O2](f: O => F2[O2]): Stream[F2, O] = {
def tapOut(o: O) = Pull.eval(f(o)) >> Pull.output1(o)
underlying.flatMapOutput(tapOut).streamNoScope
}

@deprecated("Use overload without functor", "3.7.0")
private[fs2] def evalTap[F2[x] >: F[x], O2](f: O => F2[O2], F: Functor[F2]): Stream[F2, O] =
evalTap(f)

/** Alias for `evalMapChunk(o => f(o).as(o))`.
*/
Expand Down

0 comments on commit f96c01d

Please sign in to comment.