-
Iorscala/cats2 2023. 1. 29. 16:55
문제
Join two lists of different sizes
코드
import cats.data._ import cats.syntax.all._ object IorExample { def main(args: Array[String]): Unit = { val list1: List[String] = List("x", "y") val list2: List[Int] = List(1, 2, 3, 4) val zip = list1.alignWith(list2) { case Ior.Both(a, b) => (a, b) case Ior.Left(a) => (a, 0) case Ior.Right(b) => ("z", b) } println(zip) // List((x,1), (y,2), (z,3), (z,4)) } }
'scala > cats2' 카테고리의 다른 글
Eval and Trampolining (0) 2023.07.29 Future Traverse (0) 2023.02.13 Cats2 Exercise (0) 2023.01.22 Validated (0) 2023.01.19 Writer (0) 2023.01.19