makingthematrix / signals3

A lightweight event streaming library for Scala 3
GNU General Public License v3.0
13 stars 1 forks source link

Better support for boolean events #4

Closed makingthematrix closed 1 year ago

makingthematrix commented 1 year ago

In wire-android we often made decisions based on comparison of values of different signals. It looks something like this:

for {
  a <- signalA
  b <- signalB
} yield
  if (a == b) doThis()
  else doThat()

or:

signalA.zip(signalB).map {
  case (a, b) if a == b => doThis()
  case _ => doThat()
}

In short, a lot of logic was based on comparing signals values, creating a boolean signal, and then doing something with it. For that I could introduce a compare method:

def compare(otherSignal: Signal[V])(check: (V, V) => Boolean): Signal[Boolean]

Here in signals3 I already implemented methods and and or in Signal - they can be used only if the signal is of a type that can be used as a boolean. I can develop it more: