Functional Reactive Programming

Reference
// Impure
public int total = 0
public void imp(int a, int b) {
this.total = a + b;
}
// Pure
public int pure(int a, int b) {
return a+b;
}
  • Backpressure: backpressure is in broader context exactly what it seems like, opposing the pressure coming from one end or the pipe/stream. It means the ability for the consumer to signal the producer that the rate of emission is too high; Reactive streams allow the consumer to signal how much it can process at a time.
  • Obervable: An observable can be thought of as the producer of events in Reactive Programming where it is the entity that is producing a stream of events for the observer to see. Each observable can have multiple observers and they are inherently lazy (they emit functions only when a signal is passed) and don’t produce data until an observer has subscribed to it.
  • Non-blocking: non-blocking methods are the ones that execute asynchronously. Blocking happens when your code needs to wait for execution to finish for something like an external call. Reactive systems are inherently non blocking because of the async architecture that they use.
Flux
.fromIterable(List.of(2, 3, 4, 5, 6, 7, 8)) // create a reactive stream
.filter(num -> num > 4)
.map(num -> num*num)
  • Functional Reactive Programming has a standard mechanism for error propagation. It has a specific channel that an observer can listen to for errors being propagated from the other side.
  • It can make handling UI updates very easy. Button clicks or key presses can easily be “reacted to” and updates can be made to the UI easily.
  • FRP can manage to have lower number of threads since you don’t need a different thread for each time the application needs to wait for the data
  • Functional programming helps to create more readable and concise code as compared to the traditional imperative style of proactive coding.
  • Memory Expensive: Creating streams of data and processing them with functions is more memory expensive than a traditional application.
  • Learning Curve: There is a steep learning curve for developers, not only to understand the underlying architecture and behavior of the paradigm but also to shift their thinking towards more functional programming.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store