softshipper
softshipper

Reputation: 34119

Use mapN to apply values

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?

Upvotes: 0

Views: 1080

Answers (1)

Dmytro Mitin
Dmytro Mitin

Reputation: 51723

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?

Upvotes: 6

Related Questions