final case class Triple (posOdd: List[Int], posEven: List[Int], neg: List[Int]) def triple(xs: List[Int]): Triple = xs.foldLeft(Triple(Nil, Nil, Nil))( (acc, x) => if (x < 0) acc.copy(neg = x::acc.neg) else if (x % 2 == 0) acc.copy(posEven = x::acc.posEven) else acc.copy(posOdd = x::acc.posOdd) ) triple(List(2, 0, -1 , 3, 5 , -2))