functional programming - Immutable DataStructures In Scala -


we know scala supports immutable data structures..i.e each time u update list create new object , reference in heap.

example

val xs:list[int] = list.apply(22) val newlist = xs ++ (33) 

so when append second element list create new list contain both 22 , 33.this works how immutable string works in java. question each time append element in list new object created each time..this ldoes not efficient me. there special data structures persistent data structures used when dealing this..does know this?

appending list has o(n) complexity , inefficient. general approach prepend list while building it, , reverse it.

now, question on creating new object still applies prepend. note since xs immutable, newlist points xs rest of data after prepend.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -