1

Functional reactive programming implementations seem to have the observer as being passively dependent upon streams providing them with values.

Is it possible to request a new value from down stream?

For example, if I have a stream that serves co-ordinates of the apple in the game Snake, if the apple has been eaten then how can I ask for a new value?

The source stream doesn't know that a new apple is required.

This has an interesting implementation that uses recursion.

function apple() {
  var applePos = randomPos()
  return 
     position
      .filter(p => p.equals(applePos))
      .take(1)
      .flatMapLatest(apple)
      .toProperty(applePos)
} 

Is there a more straight forward way of doing this?

Perhaps I could have a stream that knows when a value has been taken and immediately generates a new one and holds it in a buffer.

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189

1 Answers1

1

The source stream doesn't know that a new apple is required.

I think that's the problem. In proper FRP, the apple function should have a parameter with a stream of apple eaten events, so that it can know when to produce a new apple.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375