scala - Determine by parameter which member to change -


The following Scala code returns a compound error in which I can not specify a value:

Simplified Example:

  class state {val a = 1val b = 2 def compute (res: => int, add: int): unit = {res = add + 123456} calculation ( A, B) Example close to my actual use:  
  class editor {var str: string = "" var cursor: int = 0 case class undostat (str: string, cursor: int) var Undostat = seek [undostat] () var redoState = Seq [UndoState] () def und (): unit = if ( UndoState.nonEmpty) {redoState = UndoState (str, cursor) +: redoState str = undoState.head.str cursor = undoState.head.cursor undoState = undoState.tail} def redo (): unit = if (redoState.nonEmpty) { UndoState = UndoState (str, cursor) +: UndoState str = redoState.head.str cursor = redoState.head.cursor redoState = redoState.tail}}  

both undo To be very similar, I would like to remove the normal code in a function, which I pass on the source / target pair as redoState / undoState and in another way Wanted

Is there any way, They want something where functions store to say? (In C ++ I will give the member an indicator in this situation).

Use return value:

  DIF calculation (add: IT): Int = {A + 123456} Val A = Compute (B) Well BB = Compute (A)  

As the reference you can do it in C ++ Scala can not be done and generally it is not what you want to do either. However, you can pass a container that contains references to an ineligible area:

  square box (var value: int) def compute (box: box, add: box): unit = {Box (A, B) calculation (B, A)  

or (A, B) calculation (A, B) a small change) compute box :

  square box (var value: int) {def compute (add: box): unit = {value = add.value + 123456}} = New Box (1) Well B = New Box (2) a.compute (b) B. Com.Put (A)  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -