Skip to content

Commit

Permalink
Fixed bugs introduced by the removal of (A, A) => Ordering from Order.
Browse files Browse the repository at this point in the history
Revealed bug wherein the fold iteratee is not behaving well with respect
to the stack.
  • Loading branch information
Kris Nuttycombe committed Feb 11, 2012
1 parent b69d80d commit 49b047f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions example/src/main/scala/scalaz/example/MixedBag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ object MixedBag extends App {
type Pair[+A] = (A, A)
type Tree[A] = Free[Pair, A]

def leaf[A](a: A): Tree[A] = Return(a)
def node[A](l: Tree[A], r: Tree[A]): Tree[A] = Suspend[Pair, A](l -> r)

implicit val pairFunctor: Functor[Pair] = new Functor[Pair] {
def map[A, B](as: Pair[A])(f: A => B) =
f(as._1) -> f(as._2)
}

def leaf[A](a: A): Tree[A] = Return(a)
def node[A](l: Tree[A], r: Tree[A]): Tree[A] = Suspend[Pair, A](l -> r)

def flattenWriter[A](t: Tree[A]): DList[A] = {
def flatten(t: Tree[A]): Writer[DList[A], Unit] = t.resume match {
case Right(a) => DList(a).tell
Expand Down
2 changes: 1 addition & 1 deletion iteratee/src/main/scala/scalaz/iteratee/EnumeratorP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class EnumeratorP[X, E, F[_]] { self =>
}

def join(other: EnumeratorP[X, E, F])(implicit order: Order[E], m: Monad[F]): EnumeratorP[X, (E, E), F] =
EnumeratorP.joinE[X, E, E, F].apply(self, other)
EnumeratorP.joinE[X, E, E, F](m, order.order).apply(self, other)

def merge(other: EnumeratorP[X, E, F])(implicit ord: Order[E], m: Monad[F]) =
EnumeratorP.mergeE[X, E, F].apply(self, other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Enumeratee2TTest extends Spec {
implicit val v = IterateeT.IterateeTMonad[Unit, Int, Id]
implicit val vt = IterateeT.IterateeTMonadTrans[Unit, Int]
implicit val mpo = MonadPartialOrder.transformer[Id, ({ type λ[β[_], α] = IterateeT[Unit, Int, β, α] })#λ]
implicit val intO = Order[Int].order _

type StepM[A] = StepT[Unit, Int, Id, A]
type IterateeM[A] = IterateeT[Unit, Int, Id, A]
Expand Down
1 change: 1 addition & 0 deletions tests/src/test/scala/scalaz/iteratee/EnumeratorPTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalazArbitrary._

class EnumeratorPTest extends Spec {
implicit val intO = Order[Int].order _
"cogroupE" should {
"work the same as directly using the nested iteratee " in {
val enum = enumPStream[Unit, Int, Id](Stream(1, 3, 3, 5, 7, 8, 8))
Expand Down
4 changes: 4 additions & 0 deletions tests/src/test/scala/scalaz/iteratee/IterateeTTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class IterateeTTest extends Spec {
(consume[Unit, Int, Id, List] &= enumStream(Stream(1, 2, 3))).runOrZero must be_===(List(1, 2, 3))
}

"fold in constant stack space" in {
(fold[Unit, Int, Id, Int](0){ case (a,v) => a + v } &= enumStream[Unit, Int, Id](Stream.fill(10000)(1))).runOrZero must be_===(10000)
}

object instances {
object iterateet {
def monad[F[_]: Monad, X, E] = Monad[({type λ[α] = IterateeT[X, E, F, α]})#λ]
Expand Down

0 comments on commit 49b047f

Please sign in to comment.