Aggregation of Properties when Binding

32 views
Skip to first unread message

Peter Jones

unread,
Mar 8, 2024, 3:57:17 PM3/8/24
to ScalaFX Users
Hi all,

In my example, I have a collection of objects which have a BooleanProperty and another single BooleanProperty.  I want to bind the value of the single property to the collection members' BooleanProperty, using a logical OR operator.  The purpose is to have any observer of the single value notified of the change in any of the collection.

I can do

changed <== _pads(0).changed || _pads(1).changed

where  changed is the single BooleanProperty I want to bind and  _pads is the collection.

What I can't work out is how to have all the collection members OR'd using an collection operator such as map() or reduce().

Can anyone give me some direction?

Thanks!

-- Peter

Jarek Sacha

unread,
Mar 11, 2024, 3:50:43 PM3/11/24
to scalaf...@googlegroups.com

See answers here: https://github.com/scalafx/scalafx/discussions/375#discussioncomment-8750971

  val e = BooleanProperty(false)
  val f = BooleanProperty(false)
  val g = BooleanProperty(false)
  val x = BooleanProperty(false)

  val bools = Seq(e, f, g)
  // Since will will be folding on OR, we will start with FALSE initial binding
  val dummyBinding = BooleanProperty(false) && BooleanProperty(false)
  x <== bools.fold(dummyBinding)(_ || _)

--
You received this message because you are subscribed to the Google Groups "ScalaFX Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalafx-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalafx-users/034325f7-a86f-4cf1-a0bf-5a091e3c8867n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages