Use mapN to apply values

我的未来我决定 提交于 2021-01-29 22:32:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!