FPSignal:
Filter:
FPLib/Classes (extension) | FP | TimerES

FPSignal
ExtensionExtension

Implementation of Functional Reactive Programming.

Description

This is port of the reactive-core library for Scala into SuperCollider.

For more info see:

http://www.reactive-web.co.cc/core/Signal

The combinators interface is essentialy a copy of reactive-banana Haskell library.

Type Classes

EventSource is an instance of the Functor and Applicative Functor Type Classes.

Instance Methods

Combinators

.changes

An EventSource which fires events every time the signal changes.

.collect

Arguments:

f

f: A => B

Discussion:

.switchTo

Arguments:

f

f: A => FPSignal[B]

Discussion:

Implementes event switching.

.inject

Allows one, in a functional manner, to respond to an event while taking into account past events. For every event t, f is called with arguments (u, t), where u is initially the value of the 'initial' parameter, and subsequently the result of the previous application of f.

Returns:

A new FPSignal that, for every event t fired by the original FPSignal, fires the result of the application of f (which will also be the next value of u passed to it). Often 'u' will be an object representing some accumulated state.

Discussion:

An FPSignal that sums all the integer values fired by the parent FPSignal.

.selfSwitch

switching based on the the signal itself

Arguments:

f

function A -> FPSignal[ T(A, Option[B]) ]

Returns:

FPSignal[A]

Discussion:

Given an initial signal sigA of type FPSignal[ T(A, Option[B]) ], calling selfSwitch on it with a function f that evaluates to another signal sigB of type FPSignal[ T(A, Option[B]) ] will behave like sigA while the value of sigA is T(x, None()). When a value of type T(x,Some(v)) is received the function f is evaluated with v and sigA is switched out, sigB is switched in taking the role of sigA and repeating the procedure ad infinitum. This is a sort of recursive switching.

If this was a function it would have type

FPSignal[ T(A, Option[B]) ] -> ( A -> FPSignal[ T(A, Option[B]) ] ) -> FPSignal[A]

NOTE: If the initial signal can be generated from f given an initial value initVal then we can use for convenience

which is equivalent to

<*>

Applicative functor. Apply a time-varying function to time-varying value.

.when

Arguments:

es

EventStream[A]

Returns:

EventStream[A]

Discussion:

When an event arrives from es, if this signal contains the true value then the event goes through.

.if

Arguments:

trueES

EventStream[A]

falseES

EventStream[A]

Returns:

EventStream[A]

Discussion:

If the current value of this signal is true then events from trueES pass through, otherwise events from falseES pass trough.

Utilities

.expexp

.explin

.linexp

.linlin

.lincurve

.curvelin

.nexp

.nlin

.storePrevious

.mapWith

Map value with spec

Event Network - Monadic interface

.reactimate

Returns:

nil

Discussion:

This FPSignal should carry values of class IO with actions to be performed. This method should be called when defining an EventNetwork with the monadic interface.

.debug

Event Network - Imperative interface

.enOut

This FPSignal should carry values of class IO with actions to be performed. This method should be called when defining an EventNetwork with the monadic interface. The action which is the current value of the FPSignal will be executed when the network is compiled. This usefull for initialization.

.enDebug

Post incoming values to the post window with label.

NNdef

.enKr

.enKrUni

.enAr

.enArUni

Perform Side-Effects

Usually FPSignal child classes should be used inside an ENdef or NNdef. Nevertheless it is possible to add call-backs directly, although this is not recommended:

.do

When the Signal changes, runs f with new value.

.doDef

Run f every time a new event arrives and save the function using the name given

Arguments:

name

A key

f

The function to call

Returns:

Unit

.stopDoing

Stop running function f.

Arguments:

f

A function

Returns:

Unit

Disconnect from network

Usually FPSignal child classes should be used inside an ENdef or NNdef. It is possible to manipulate the FRP graph directly, although this is not recommended:

.remove

Disconnects this FPSignal from the parent FPSignal (if it has a parent). If the FPSignal is not assigned to any variable anymore it will be gc'ed.

.reset

Removes all listeners. This will disconnect this EventSource from the rest of the chain that depends on it, and the rest of the chain will be gc'ed.