Gabriel95 / scalafx

Automatically exported from code.google.com/p/scalafx
Other
0 stars 0 forks source link

Complex bindings between collections #112

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This is rather pie-in-the-sky, but it would be awesome if we could do bindings 
between observable collections with collection operations (map, filter, etc) in 
between.

For instance, suppose I have an ObservableBuffer `a` that I want to bind to 
another ObservableBuffer `b`, but I also want `b` to always start with a couple 
of elements that don't appear in `a`.

A regular Scala collection view can be made to do this, like so:

    val a = Buffer(3, 4, 5)
    val b = 1 +: 2 +: a.view
    // b contains: 1, 2, 3, 4, 5

Here, changes to `a` are reflected in `b`:

    a += 6
    b.mkString(", ")  // returns "1, 2, 3, 4, 5, 6"

But this isn't a binding—`b` isn't a mutable collection exposed by some 
JavaFX control. It's also not observable—even if `a` produces events, `b` 
doesn't. How to bridge that gap, I don't know, but I thought I'd submit the 
idea anyway.

Original issue reported on code.google.com by argv.min...@gmail.com on 26 Nov 2013 at 7:32