user1809095
user1809095

Reputation: 411

Scala loop over sequence of user defined classes

I have a function which receives a sequence of two user defined classes:

tags: Seq[(tag, pattern)]

I want to access each element of sequence then access to fields belonging to tag and pattern from that element. I am able to print all sequence lines using:

for(i <- tags)
  {
    println("Tags for i are " + i)
  }

But how can I access tag and pattern from i?

Upvotes: 0

Views: 291

Answers (1)

bjfletcher
bjfletcher

Reputation: 11508

You can use:

for ((t, p) <- tags) {
  println(s"Tag: $t Pattern: $p")
}

Upvotes: 1

Related Questions