Author Topic: Question regarding consecutive id in set  (Read 705 times)

Offline gauss71248

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Question regarding consecutive id in set
« on: August 18, 2015, 08:47:14 AM »
Hi, can anyone help me?

I have a blackout. I have a class edge (like in a graph) with the following signature.

Code: [Select]
class Edge(b1: Block, b2: Block, var id: Int, arity: Int)
Block is a class - what it does is not ineresting.
Now, there is already a set s with some objects that provide the source and targets. I would now like to give those edges a consecutive id (starting by 1, next block shall get 2, and so on....) I currently did this by 1) giving all a 1 as id and later on I run a function createLabels that re-assigns the labels (see below).

Code: [Select]
val edges = s map { x => new Edge(x.getSrcBlock, x.getDstBlock, 1, getArity(x))}

def createLabels: Unit = {var i: Int =0; for(e<- edges) {

However, I don't like this solution because I want to avoid those var variables and it is procedural style rather than functional style. Can you give me a hint how I could do this better?

Thanks a lot!

Offline NickR

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 0
    • View Profile
Re: Question regarding consecutive id in set
« Reply #1 on: September 11, 2015, 09:45:25 AM »
These forums are for the Scala digital signage platform, not the Scala programming language that is based on Java.  You may find better responses on a forum dedicated to Scala Lang.