I'm trying to use an Either as the result of an algebra using Free monad, like the following code
///// Command
sealed trait Command[A]
type Result[A] = Either[Exception, A]
object Command {
case class Tell(line: String) extends Command[Result[Unit]]
case class Ask(line: String) extends Command[Result[String]]
}
type App[A] = EitherK[Command, Log, A]
def program(implicit L: LogOps[App],
C: CommandOps[App]): Free[App, Unit] =
for {
_ <- L.show("start <ask>")
name <- C.ask("What's your name?")
_ <- L.show("start <tell>")
_ <- C.tell(s"Hi <$name>, nice to meet you!")
_ <- L.show("done.")
} yield ()
...
the problem is that the name is an Either, so I got the following output
L--- start <ask>
What's your name?
George
L--- start <tell>
Hi <Right(George)>, nice to meet you!
L--- done.
Any idea?
Thanks