1

I have a Binding[Seq[T]].

I want to create a BindingSeq[T] in a way that, whenever I change the Seq the BindingSeq will change in the same way.

How can I do this?

Yang Bo
  • 3,586
  • 3
  • 22
  • 35
jens
  • 453
  • 2
  • 12
  • What exactly do you mean by the latter part of your question? Do you want `BindingSeq` to change if you change the `Seq` stored in your first variable, or if you change something inside the mutable `Seq` itself? I don't think the latter is possible. – Adowrath Feb 14 '18 at 08:34
  • The Seq is immutable. Sorry, should have made this clear. – jens Feb 14 '18 at 09:51

1 Answers1

2

You can convert a Binding[Seq[T]] to a BindingSeq[T].

def convert1[T](bindingOfSeq: Binding[Seq[T]]): BindingSeq[T] = {
  Constants(bindingOfSeq).flatMap { bindingOfSeq =>
    Constants(bindingOfSeq.bind: _*)
  }
}

or

def convert2[T](bindingOfSeq: Binding[Seq[T]]): BindingSeq[T] = {
  SingletonBindingSeq(bindingOfSeq).flatMap { seq =>
    Constants(seq: _*)
  }
}

However, the Seq, if it is a mutable Seq, has no magic data-binding ability.

When you change the content of the Seq, nothing happens.

Yang Bo
  • 3,586
  • 3
  • 22
  • 35