Skip to content

Commit

Permalink
Generalized mapAccumM signature #1029 (#1037)
Browse files Browse the repository at this point in the history
* Generalized mapAccumM signature

* Fixed weird compiler error with explicit type parameters
  • Loading branch information
andreamarcolin authored and iravid committed Jun 20, 2019
1 parent ff9cb76 commit 9118819
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion streams/jvm/src/test/scala/zio/stream/StreamSpec.scala
Expand Up @@ -600,7 +600,7 @@ class ZStreamSpec(implicit ee: org.specs2.concurrent.ExecutionEnv)
}

private def mapAccumM = {
val stream = Stream(1, 1, 1).mapAccumM(0)((acc, el) => IO.succeed((acc + el, acc + el)))
val stream = Stream(1, 1, 1).mapAccumM[Any, Nothing, Int, Int](0)((acc, el) => IO.succeed((acc + el, acc + el)))
(slurp(stream) must_=== Success(List(1, 2, 3))) and (slurp(stream) must_=== Success(List(1, 2, 3)))
}

Expand Down
8 changes: 4 additions & 4 deletions streams/shared/src/main/scala/zio/stream/ZStream.scala
Expand Up @@ -389,11 +389,11 @@ trait ZStream[-R, +E, +A] extends Serializable { self =>
* Statefully and effectfully maps over the elements of this stream to produce
* new elements.
*/
final def mapAccumM[E1 >: E, S1, B](s1: S1)(f1: (S1, A) => IO[E1, (S1, B)]): ZStream[R, E1, B] =
new ZStream[R, E1, B] {
override def fold[R1 <: R, E2 >: E1, B1 >: B, S]: Fold[R1, E2, B1, S] =
final def mapAccumM[R1 <: R, E1 >: E, S1, B](s1: S1)(f1: (S1, A) => ZIO[R1, E1, (S1, B)]): ZStream[R1, E1, B] =
new ZStream[R1, E1, B] {
override def fold[R2 <: R1, E2 >: E1, B1 >: B, S]: Fold[R2, E2, B1, S] =
ZManaged.succeedLazy { (s, cont, f) =>
self.fold[R1, E2, A, (S, S1)].flatMap { fold =>
self.fold[R2, E2, A, (S, S1)].flatMap { fold =>
fold(s -> s1, tp => cont(tp._1), {
case ((s, s1), a) =>
f1(s1, a).flatMap {
Expand Down

0 comments on commit 9118819

Please sign in to comment.