첫 번째 오류가 발생한 후에 유효성 검사가 중지되도록 아래에 유효성 검사 함수를 작성하려고합니다. 반환 유형 three
은 다른 기능과 다릅니다. 이 코드를 컴파일하기 위해 어떤 모나드 변환기를 사용해야합니까?어떤 Monad Transformer를 사용할 수 있습니까?
import scalaz._
import Scalaz._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
def one(a : String): Disjunction[Int, String] =
a == "one" match {
case true => \/-("one")
case false => -\/(2)
}
def two(a : String): Disjunction[Int, String] =
a == "two" match {
case true => \/-("two")
case false => -\/(3)
}
def three(a : String): Future[Disjunction[Int, String]] =
Future (a == "three") map {
case true => \/-("three")
case false => -\/(4)
}
def validate(a : String) = for {
e1 <- one(a)
e2 <- two(a)
e3 <- EitherT(three(a))
} yield (e1 |+| e2 |+| e3)
컴파일 오류 :이 같은 상황에서 취할 수있는 두 가지 일반적인 방법이 있습니다
Error:(27, 7) type mismatch;
found : scalaz.EitherT[scala.concurrent.Future,Int,String]
required: scalaz.\/[?,?]
e3 <- EitherT(three(a))
^
Error:(66, 7) type mismatch;
found : scalaz.EitherT[scala.concurrent.Future,Int,String]
required: scalaz.\/[?,?]
e3 <- EitherT(three(a))
^
'미래'또는 '기다림'에서 '3'의 결과로 '1'과 '2'를 모두 감싸지 않는 이유는 무엇입니까? –
당신은'EitherT' 모나드 변압기를보고 싶습니다. 세번째'<'는'String'을 리턴하지 않고,'Disjunction'을 당신에게주고 싶습니다. 처음 두 개는' 문자열 ')의 일부입니다. –
@EndeNeu EitherT를 시도했지만 여전히 컴파일 오류가 발생합니다. 컴파일 오류와 함께 업데이트 된 질문을 참조하십시오. 전에 DisjunctionT를 사용하고 있었는데 (이것은 EitherT의 래퍼 일뿐입니다) 동일한 결과가 있습니다. –