what you’d like is something like a couple of MVar...
# arrow
p
what you’d like is something like a couple of MVars that you update with the latest value, that you combine with
Applicative.map
into an Either or an Option
👍 1
m
Rx is working fine - but that's the only use case left I'd need it for. Will give MVars a try, thanks!
👌🏼 1
p
to do multiple results you’ll need a recursive function
so you do your operation, whether it succeeds or fails you then call yourself with the right parameters
Copy code
fun validate(ioA: IO<Int>, ioB: IO<String>): IO<Unit> =
  map(ioA, ioB) { a, b ->
    val vb = isValid(b)
    when(val va = isValid(a)) {
      true -> when (vb) {
        true -> nextStep(a + b)
        false -> validate(just(a), ioB) // wrong
      }
      false -> when (vb) {
        true -> validate(ioA, just(b)) // wrong
        false -> validate(ioA, ioB)
      }
    }
  }
see if that makes sense to you
if we had pattern matching we wouldn’t need nested when-s
validate(mVarA.take(), mVarB.take())
to start it
…actually
hmmmm
you may find a problem if there’s a new value that’s not valid anymore and we’re passing around that
just
we don’t have the equivalent of
combineLatest
, so what we’re doing here is reproducing it’s behavior
Copy code
fun Concurrent<ForIO>.pollNextTickOnTimeout(curr: A, next: IO<A>): IO<A> =
  IO.schedulers().default().raceN(
    Timer(this)
      .sleep(100.milliseconds)
      .flatMap { just(a) }, 
    next
  )
with that
Copy code
fun Concurrent<ForIO>.validate(ioA: IO<Int>, ioB: IO<String>): IO<Unit> =
  map(ioA, ioB) { a, b ->
    val vb = isValid(b)
    when(val va = isValid(a)) {
      true -> when (vb) {
        true -> nextStep(a + b)
        false -> validate(pollNextTickOnTimeout(a, ioA), ioB)
      }
      false -> when (vb) {
        true -> validate(ioA, pollNextTickOnTimeout(b))
        false -> validate(ioA, ioB)
      }
    }
  }
j
Is ^ missing an
ioB
?
validate(ioA, pollNextTickOnTimeout(b, ioB))
👍🏼 1
m
Thanks, guys! I simplified my approach to changing the contract between sender and receiver to deliver all textfield contents when one of them is updated - that's more a hack (that does not scale well), but still the most concise solution. I really do not want to introduce a timer for that.