Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the corresponding concepts of Event and Behavior from FRP in RxScala?

By looking at the Scaladoc of RxScala it is not clear to me how to map the concepts of Signal, Event and Behavior from FRP to RxScala.

I also took the Coursera Reactive course but the connection between FRP (as described by Conal Elliott) and RxScala was not explained. My vague feeling is that Observables in RxScala correspond to Behaviors/Signals in FRP but I am not quite sure.

Could someone please explain how to map concepts of Conal's FRP (Signal, Signal transformer, Event, Behavior) to the concepts/classes ( Future/ Observable/ Scheduler/ Subject) defined in RxScala?

like image 582
jhegedus Avatar asked Oct 20 '22 11:10

jhegedus


1 Answers

Conal's Signal is equivalent to the wiki's Behavior, they are Time -> a although Behavior has a newtype wrapper around it. Event is just a Signal composed with Maybe.

RxScala's Scheduler appears to be the FRP implementation / plumbing not directly related to the interface that Programmers would use for building an FRP application (GUI or no). I'd wager a lot of Haskell FRP takes advantage of non-strictness so "schedule" future events, but that is not kind to performance on the JVM (in particular) so, the scheduler trait is used for that.

RxScala's Observable trait is the common interface for Signals, and would be implemented directly by primitive / base Signals, i.e. those are aren't composed from other signals. The Observable object serves as a bit of a Factory and a bit as a combinator library, provding way of promoting various values to the FRP framework as well as some ways to combine existing Observable instances.

RxScala's Subject trait is for user-defined derived Signals, i.e. those dependent on other Observables. To be dependent on an Observable in RxScala, you have to implement Observer. Subject only adds two methods on top of the combination of Observer and Observable -- the functions for conversion to the Java Rx framework.

The derived signals produce by the Observable object's combinators may implement Subject, but are only guaranteed to implement Obervable. It seems like Subject is specifically for when you have a unique/custom/unusual manner for "wiring" incoming Notifications to outgoing Notifications, particularly if it is something stateful.

HTH. This is the first time I've more than scanned the RxScala docs, so it's likely I missed something.

like image 178
Boyd Stephen Smith Jr. Avatar answered Oct 23 '22 06:10

Boyd Stephen Smith Jr.