From 813ce28d9015def953b06246cc54626054b54a43 Mon Sep 17 00:00:00 2001 From: pkiersznowski Date: Wed, 29 Nov 2023 15:54:39 +0100 Subject: [PATCH] add map/flatmap overrides --- src/main/scala/pl/iterators/sealedmonad/Sealed.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/scala/pl/iterators/sealedmonad/Sealed.scala b/src/main/scala/pl/iterators/sealedmonad/Sealed.scala index 244a8bc..4d91878 100644 --- a/src/main/scala/pl/iterators/sealedmonad/Sealed.scala +++ b/src/main/scala/pl/iterators/sealedmonad/Sealed.scala @@ -433,6 +433,10 @@ object Sealed extends SealedInstances { case Fold(prev, l, r) => F.pure(Left(Fold(prev, runCont(l.asInstanceOf[ADT => Sealed[F, A0, ADT]]), runCont(r)))) case _ => sys.error("impossible") } + + override def map[B](f: A => B) = this.copy(cont = cont andThen (_.map(f))) + + override def flatMap[B, ADT1 >: ADT](f: A => Sealed[F, B, ADT1]): Sealed[F, B, ADT1] = this.copy(cont = cont andThen (_.flatMap(f))) } private[sealedmonad] final case class Effect[F[_], A](fa: Eval[F[A]]) extends Sealed[F, A, Nothing] {