скаляр либо получи опцию внутри будущего - PullRequest
0 голосов
/ 04 апреля 2020

Я заблудился, потеряв скалярные дизъюнкции. Следующие «работы», я полагаю

def attributeFromObject(id: String): Future[String \/ String] = {
    val aSection = lookupObject(id) // may fail ... 
    val whatsHappening = for (
        aSection: AnObject <- eitherT(aSection);
        temp = aSection.attribute // attribute *should* be an option, but that causes pain, so in the case class I remapped the option to an either via def
    ) yield {
         temp
    }
    whatsHappening.run.map(_.flatMap(identity)) // and ?????? somehow I think this "combinbes" the two disjunctions to prevent a signature of Future[String \/ (String \/ String)]
}

case class AnObject(attributes: Attributes) {
    def attribute : String \/ String = this.attributes.attribute match {
        case Some(attribute ) => attribute .right
        case None => "No attribute found for section".left
}

Существует ли идиоматический c способ решения Future ["any -> option"] проблемы с отказоустойчивостью в scalaz? Это решение «работает», но я чувствую, что упускаю что-то важное, потому что оно как бы тонет в шаблоне!

...