deasq
deasq

Reputation: 11

how to initialize a class, detail shown below

I have a WhitelistThunk method which take no parameters and return a list of Whitelist, how to initialize this AuthorizedServicesImpl class?

sealed trait WhitelistConcern extends Product with Serializable

  object WhitelistConcern {
    case class Whitelist(accountId: String, ruleName: String) extends WhitelistConcern
    case class whi(accountId: String) extends WhitelistConcern
  }

  type WhitelistThunk = () => List[Whitelist]

class AuthorizedServicesImpl(
 draxWhitelist : => Map[String, WhitelistThunk]){}

This can convert type from list of string to list of Whitelist.

lazy val pattrn = "([^:]*):([^:]*)".r
  lazy val patt = "([^:]*)".r
  lazy val sdcWhitelistHelper = () => new SDCWhitelistHelper(configuration, sdcRetriever).whitelistSentToDrax.collect{
    case pattrn(accnt, rule) => Whitelist(accnt, rule)

  }

  lazy val sdcWhitelistHelper1 = () => new SDCWhitelistHelper(configuration, sdcRetriever).whitelistSentToDrax.collect{
    case patt(accnt) => whi(accnt)
  }

This is what im doing now, but the error is

Required scala.Predef.Map [scala.Predef.String, WhitelistThunk]
Found scala.collection.immutable.Map[java.lang.String, List[Whitelist]]
 private lazy val authorizedServices =
    new AuthorizedServicesImpl(
      Map("whitelist" -> WhitelistHelper),
    )

Upvotes: 1

Views: 55

Answers (1)

Tim
Tim

Reputation: 27421

WhitelistHelper is a List[Whitelist] but you need () => List[Whitelist], so update the declaration like this:

lazy val WhitelistHelper = () => new Helper(configuration, Retriever) ...

or change the class creation like this:

new AuthorizedServicesImpl(
  Map("whitelist" -> (() => WhitelistHelper)),
)

Upvotes: 1

Related Questions