0
이 작동 :해당 옵션의 시퀀스 및 트래버스 방법은 무엇입니까? scalaz 7.2.6에
// import scalaz.syntax.traverse._
List(1.some, 2.some, 3.some).sequence
res12: Option[List[Int]] = Some(List(1, 2, 3))
List(1.some, none, 3.some).sequence
res13: Option[List[Int]] = None
def doubleSmall(x: Int) = if (x < 30) (x * 2).some else none
List(1,2,3).traverse(doubleSmall)
res15: Option[List[Int]] = Some(List(2, 4, 6))
다음 코드는 컴파일되지 않습니다. \/
에 Option
의 sequence
및 traverse
개의 메소드가 있습니까?
List(1.right, 2.right, 3.right).sequence
expecting something like: List(1, 2, 3).right
List(1.right, "error2".left, "error3".left).sequence
expecting something like: Seq("error2", "error3").left
val doubleSmall(x: Int) = if (x < 30) (x * 2).right else "error".left
List(1,2,3).traverse(doubleSmall)
왼쪽에 하나 이상의 문자가있는 경우 첫 번째 문자 만 사용됩니다. 그러나 어쨌든 나는 그 단순성 때문에 대답을 받아 들일 것이다. 왼쪽 목록을 얻는 방법에 대한 좀 더 자세한 질문을 올렸습니다. http://stackoverflow.com/questions/39471935/scalaz-disjunction-sequence-returning-a-list-of-lefts –