Welcome! Got a question? Do you have -Ypartial-unification turned on? Other FAQs: http://typelevel.org/cats/faq.html
import cats.implicits._, cats.syntax.all._, cats.data.Kleisli._
val k1: Kleisli[Option, Int, Int] = Kleisli(x => Option(x))
val k2 = k1
k1 >>> k2 // no can compiley yoooooooooooooooooo
i have a naive question
case class TeacherId(id:Int)
case class StudentId(id:Int)
case class EClasse(teacherId: TeacherId,students:List[StudentId]=List())
val o: Seq[EClasse] = List(
EClasse(TeacherId(1),List(StudentId(1))),
EClasse(TeacherId(1),List(StudentId(2))),
EClasse(TeacherId(1),List(StudentId(3))),
EClasse(TeacherId(2),List(StudentId(8))),
EClasse(TeacherId(2),List(StudentId(3))),
EClasse(TeacherId(2),List(StudentId(5)))
)
how can i combine all of them into
List(
EClasse(TeacherId(1),List(StudentId(1),StudentId(2),StudentId(3))),
EClasse(TeacherId(2),List(StudentId(5),StudentId(3),StudentId(8)))
)
using cats?
val res =
o.foldMap(ec => Map(ec.teacherId -> ec.students)).map { case (k, v) => EClasse(k, v) }.toList
o
is typed as List[EClasse]
, and not Seq
import cats.implicits._
A
s into a single A
, and an identity element of type A