Reputation: 721
I'm new to scala and I'm trying to get to construct a list from another one which I get from a scala object this is my model:
case class Session(
_id: Option[String],
participants: Option[Seq[Participant]])
case class Participant(
contact: Contact,
participantStatus: Option[String])
Contact.scala
case class Contact(
firstName: Option[FirstName],
lastName: Option[LastName],
address: Option[Address])
Address.scala
case class Address(
email: Option[String])
using this loop:
for (s <- session.participants) println(s)
I get :
List(Participant(Contact(Some(FirstName(5m,Some(5),Some(5))),Some(LastName(5,Some(5),Some(5))),Some(Address(None,None,None,None,None,Some(5),Some(5),Some(5),Some([email protected]),None)),None,None),None), Participant(Contact(Some(FirstName(contact1,Some(contact1),Some(contact1))),Some(LastName(contact1,Some(contact1),Some(contact1))),Some(Address(None,None,None,None,None,Some(1),Some(1),Some(1),Some([email protected]),None)),None,None),None))
when I try : println(s.contact)
I get : value contact is not a member of Seq[models.Session.Participant]
Upvotes: 0
Views: 53
Reputation: 3921
Your s
variable is getting pulled out from session.participants
which has type Option[Seq[Participant]]
, so you get Seq[Participant]
. If you want to loop through your participants, you need a list/seq, so:
val sessionParticipants = session.participants.getOrElse(Seq.empty)
for (s <- sessionParticipants) println(s)
Upvotes: 3