问题
I have the following code snippet:
final case class Configuration(env: Env, user: String, password: String, address: String)
trait DbSetup[F[_]] {
type EnvT[A] = OptionT[F, A]
def system: EnvT[Env]
def user: EnvT[String]
def password: EnvT[String]
def address: EnvT[String]
}
object DbSetup {
def get[F[_] : Monad](s: DbSetup[F]): s.EnvT[Configuration] = ???
}
How to use Applicative function mapN
in the implementation of get
function to get Configuration
filled?
回答1:
Try
import cats.syntax.apply._
def get[F[_] : Monad](s: DbSetup[F]): s.EnvT[Configuration] =
(s.system, s.user, s.password, s.address).mapN(Configuration)
May I recommend you to read Herding Cats or Scala with Cats?
来源:https://stackoverflow.com/questions/62224033/use-mapn-to-apply-values