Obyi O.

asked • 09/06/22

From method fetchDiagnosisForUniqueCodes, I would like to return Future[List[DiagnosisCode]]

// This is my requirement
// getAllUniqueCodes codes,
// map over getAllUniqueCodes and then
// call fetchDiagnosisForUniqueCode that returns Future[List[DiagnosisCode]]

case class DiagnosisCode(rootCode: String, uniqueCode: String, description: Option[String] = None)

object Database {
private val data: List[DiagnosisCode] = List(
DiagnosisCode("A00", "A001", Some("Cholera due to Vibrio cholerae")),
DiagnosisCode("A00", "A009", Some("Cholera, unspecified")),
DiagnosisCode("A08", "A080", Some("Rotaviral enteritis")),
DiagnosisCode("A08", "A083", Some("Other viral enteritis")),
DiagnosisCode("B15", "B150", Some("Hepatitis A with hepatic coma")),
DiagnosisCode("B15", "B159", Some("Hepatitis A without hepatic coma")),
DiagnosisCode("H26", "H26001", Some("Other cataract right eye")),
DiagnosisCode("H26", "H26002", Some("Other cataract left eye"))
)
def getAllUniqueCodes: Future[List[String]] = Future {
Database.data.map(_.uniqueCode)
}

def fetchDiagnosisForUniqueCode(uniqueCode: String): Future[Option[DiagnosisCode]] = Future {
Database.data.find(_.uniqueCode.equalsIgnoreCase(uniqueCode))
}

}

// ------Kindly find the problem below---------------------

PlainBashC++C#CSSDiffHTML/XMLJavaJavascriptMarkdownPHPPythonRubySQL

def fetchDiagnosisForUniqueCodes/*: Future[List[DiagnosisCode]]*/ = {
Database.getAllUniqueCodes.map { (xs: List[String]) =>
xs.map { (uq: String) =>
Database.fetchDiagnosisForUniqueCode(uq)
}
}
}

1 Expert Answer

By:

Bezalel P. answered • 03/20/26

Tutor
New to Wyzant

Self Learner teaching others how to learn and solve their problem

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.