Given:  def rights[A, B](xs: Seq[Either[A, B]]): Seq[B] =    xs.flatMap {      case Right(x) => List(x)      case Left(_)  => List.empty    }  def lefts[A, B](xs: Seq[Either[A, B]]): Seq[A] =    xs.flatMap {      case Right(_) => List.empty      case Left(x)  => List(x)    }  def combine[A, B](xs: Seq[A], ys: Seq[B]): Seq[Either[A,B]] = {    val l: Seq[Either[A, B]] = xs.map(Left[A,B](_))    val r: Seq[Either[A, B]] = ys.map(Right[A,B](_))    l ++ r  }Is there a better way to do the following, i.e. apply distinct to the Right[Int] in the Seq[Either[String, Int]].Look to res1 in the below output as the desired output.scala> val xs: Seq[Either[String, Int]] = List( Left(foo), Right(42), Right(6), Right(42) )xs: Seq[Either[String,Int]] = List(Left(foo), Right(42), Right(6), Right(42))scala> val distinct = rights(xs).distinctdistinct: Seq[Int] = List(42, 6)scala> combine(lefts(xs), distinct)res1: Seq[Either[String,Int]] = List(Left(foo), Right(42), Right(6))
Applying Function to `Seq[B]` in `Seq[Either[A, B]]`
scala