getting list from scala object

Rajeun

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]

insan-e

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)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting an element from a Scala Seq (list) by property

From Dev

Object is not getting removed properly from Array list

From Dev

Getting distinct object from list in java

From Dev

get java object array from scala list

From Dev

Getting case object instances which derive from a sealed parent in Scala

From Dev

Scala/Play - Building an aggregated JSON by getting partial data from the list

From Java

Getting the largest value from an object in a list in another list [C#]

From Dev

Scala standalone object not getting recognized

From Dev

Getting object list in Knapsack

From Dev

Getting object with max date property from list of objects Java 8

From Dev

Getting a list of attachments from Swift_Message object

From Dev

Not getting list of parse object I am fetching from parse

From Dev

Getting the object of selected element from a list of elements Angular 4

From Dev

Filter out duplicates from List[Either[Object, Exception]] in scala

From Dev

Converting to/getting original list object from string representation of original list object in python

From Dev

Getting max from a case class List of nodes, returning Scala Option[List]

From Dev

Changing an object property from an object list - every object is getting the property changed

From Dev

Getting values from list

From Dev

Getting a list of list from a string

From Dev

Scala Macros: Getting a List of TypeSymbols to be used at runtime

From Dev

Getting a File object from FileInputStream

From Dev

Getting A Selected Object from GridView

From Dev

Getting value from a collection object

From Dev

Getting settings object from the buildscript

From Dev

Getting an object from its address

From Dev

Getting A Selected Object from GridView

From Dev

Getting value from object in javascript

From Dev

Getting tag of object from UITapGestureRecognizer

From Dev

Getting Route object from GetResponseEvent

Related Related

  1. 1

    Getting an element from a Scala Seq (list) by property

  2. 2

    Object is not getting removed properly from Array list

  3. 3

    Getting distinct object from list in java

  4. 4

    get java object array from scala list

  5. 5

    Getting case object instances which derive from a sealed parent in Scala

  6. 6

    Scala/Play - Building an aggregated JSON by getting partial data from the list

  7. 7

    Getting the largest value from an object in a list in another list [C#]

  8. 8

    Scala standalone object not getting recognized

  9. 9

    Getting object list in Knapsack

  10. 10

    Getting object with max date property from list of objects Java 8

  11. 11

    Getting a list of attachments from Swift_Message object

  12. 12

    Not getting list of parse object I am fetching from parse

  13. 13

    Getting the object of selected element from a list of elements Angular 4

  14. 14

    Filter out duplicates from List[Either[Object, Exception]] in scala

  15. 15

    Converting to/getting original list object from string representation of original list object in python

  16. 16

    Getting max from a case class List of nodes, returning Scala Option[List]

  17. 17

    Changing an object property from an object list - every object is getting the property changed

  18. 18

    Getting values from list

  19. 19

    Getting a list of list from a string

  20. 20

    Scala Macros: Getting a List of TypeSymbols to be used at runtime

  21. 21

    Getting a File object from FileInputStream

  22. 22

    Getting A Selected Object from GridView

  23. 23

    Getting value from a collection object

  24. 24

    Getting settings object from the buildscript

  25. 25

    Getting an object from its address

  26. 26

    Getting A Selected Object from GridView

  27. 27

    Getting value from object in javascript

  28. 28

    Getting tag of object from UITapGestureRecognizer

  29. 29

    Getting Route object from GetResponseEvent

HotTag

Archive