In my application I have use some "data" ValueCell
(something like 20) and I would like to create a ValueCell
which would be used to detect if any of my "data" ValueCell
was updated . So I would like this cell to change whenever one of the other cells are changed.
Here is a simple code example
class StringFilter {
val referenceList = "foo"::"bar"::"scala"::"lift"::Nil
val length = ValueCell[Int](3)
val content = ValueCell[String]("")
//Here I put some functions to update length or prefix on my webpage
def filter(s:String):Boolean = (s.length==length.get)&&(s.contains(content.get))
val changed =ValueCell[???](???)
val results= changed.lift(referenceList.filter)
}
What should I put instead of ???
? I am also open to solutions which are not using ValueCells, even if I will in the end need some cells because I have to use WiringUI.
Edit: length
and content
don't need to be cells but they need to be settable
Edit: After some more research I came to an idea: implement a case class
like SeqCell
but which would not take a type for the Cells in parameter, and for an arbitrary number of cells. Is it possible?
Here is the implementation of SeqCell
:
final case class SeqCell[T](cells: Cell[T]*) extends Cell[Seq[T]] {
cells.foreach(_.addDependent(this))
/**
* The cell's value and most recent change time
*/
def currentValue: (Seq[T], Long) = {
val tcv = cells.map(_.currentValue)
tcv.map(_._1) -> tcv.foldLeft(0L)((max, c) => if (max > c._2) max else c._2)
}
/**
* If the predicate cell changes, the Dependent will be notified
*/
def predicateChanged(which: Cell[_]): Unit = notifyDependents()
}
Edit: In scala Cell
is not covariant, so it seems like I won't be able to make a SeqCell
out of my multiple typed cells. I would really appreciate a global solution for an arbitrary number of cells.