This page is no longer maintained — Please continue to the home page at

Change detection in immutable data collections

No replies
John Ky
Joined: 2009-10-06,
User offline. Last seen 42 years 45 weeks ago.
Hi all,
I had just been reading about the heavy use of observable collections in JavaFX and was wondering if there were any equivalent in the functional world and in particular for Scala.
With mutable collections, the collections have the ability to register handlers to listen for changes that are made to the collection.  I can then know when an item was inserted or deleted and be able to respond appropriately.  With immutable collections, that doesn't seem to make sense because immutable collections don't change, but I can create a new immutable collection based on the old one, but containing the differences.
Now in the context of a GUI, it is desirable to be able to detect small changes in large collections.  If I insert something into my collection, I should be able to find out what I inserted so that when I render the objects to the screen, I only need to re-render whatever item was inserted.
With immutable collections, I imagine what I would do is create a new collection with the additional element and the change would be the difference between the old collection and the new one.  Is such a diff operation efficient?  And is there an efficient implementation of collection diffs in Scala?
Or perhaps I should have an observable mutable collection interface backed with immutable collections underneath or dispense with immutability altogether?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland