Skip to content

Commit

Permalink
Add direct map def on EntityT
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Chapuis authored and jchapuis committed Dec 16, 2021
1 parent ba06f65 commit b76aa76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/scala/endless/core/interpret/EntityT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ final class EntityT[F[_], S, E, A](
case Left(reason) => reason.asLeft.pure
}
})

def map[B](f: A => B)(implicit monad: Monad[F]): EntityT[F, S, E, B] =
flatMap(a => EntityT.purr(f(a)))
}

object EntityT extends EntityRunFunctions with LoggerLiftingHelper {
Expand Down
14 changes: 13 additions & 1 deletion core/src/test/scala/endless/core/interpret/EntityTSuite.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package endless.core.interpret

import cats.data.{Chain, NonEmptyChain}
import cats.laws.discipline.MonadTests
import cats.laws.discipline.{FunctorTests, MonadTests}
import cats.syntax.either._
import cats.syntax.eq._
import cats.syntax.flatMap._
Expand Down Expand Up @@ -51,6 +51,18 @@ class EntityTSuite extends DisciplineSuite {
MonadTests[EntityT[ListWrapper, State, Event, *]].monad[Value, Value, Value]
)

checkAll(
"EntityT.FunctorLaws for direct map def",
FunctorTests[EntityT[ListWrapper, State, Event, *]](
new Functor[EntityT[ListWrapper, State, Event, *]] {
override def map[A, B](fa: EntityT[ListWrapper, State, Event, A])(
f: A => B
): EntityT[ListWrapper, State, Event, B] = fa.map(f)
}
)
.functor[Value, Value, Value]
)

test("writer appends events") {
val w1 = EntityT.writer[ListWrapper, State, Event](NonEmptyChain.one(event1))
val w2 = w1 >> EntityT.writer(NonEmptyChain(event2, event3))
Expand Down

0 comments on commit b76aa76

Please sign in to comment.