EventSource:
Filter:
FPLib/Classes (extension) | FP

EventSource
ExtensionExtension

Implementation of Functional Reactive Programming.

Description

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

For more info see:

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

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

Type Classes

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

Class Methods

.zero

Returns:

EventStream[A]

Discussion:

Zero of Monoid Type Class. Returns an event source that never fires.

Instance Methods

Combinators

Methods to combine EventSource's into a network of event processing nodes. These combinators should be used inside an ENdef or NNdef.

.hold

Arguments:

initialValue

The current ('now') value for the returned FPSignal.

Returns:

An FPSignal that holds the last value of the EventSource

.collect

Returns:

A new EventStream, that for every event that this EventStream fires, that one will fire an event that is the result of applying 'f' to this EventStream's event.

Discussion:

.select

Returns:

A new EventStream that propagates a subset of the events that this EventStream fires.

Discussion:

.inject

Arguments:

initial

initialValue

f

state altering function

Returns:

A new EventStream that, for every event t fired by the original EventStream, 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:

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.

.injectSig

Arguments:

initial

initialValue

f

state altering function

Returns:

A new EventStream that, for every event t fired by the original EventStream, 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:

Creates a signal initialized with the initial state.

.injectF

Arguments:

initial

initial value

Returns:

A new EventStream that, for every event f fired by the original EventStream, fires the result of the application of f to the current state s.

.injectFSig

Arguments:

initial

initial value

Returns:

A new EventStream that, for every event f fired by the original EventStream, fires the result of the application of f to the current state s. Creates a signal initialized with the initial state.

|+|

Merges the output of the two EventSources.

Discussion:

.merge

the same as |+|

.switchTo

Create a new EventStream that consists of the events of the EventStreams returned by f. f is applied on every event of the original EventStream, and its returned EventStream is used until the next event fired by the original EventStream, at which time the previously returned EventStream is no longer used and a new one is used instead.

Arguments:

f

f the function that is applied for every event to produce the next segment of the resulting EventStream.

initES

the initial EventStream to use.

Discussion:

Persistable nodes

.holdStore

.injectFSigStore

.injectFStore

Utilities

.expexp

.explin

.linexp

.linlin

.lincurve

.curvelin

.nexp

.nlin

.storePrevious

.selectSome

.paged

.mapWith

Map value with spec

.onlyChanges

Block values which are equal to the last value.

Event Network - Monadic interface

.reactimate

Returns:

nil

Discussion:

This EventStream 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 EventStream should carry values of class IO with actions to be performed. This method should be called when defining an EventNetwork with the monadic interface.

.enDebug

Post incoming values to the post window with label.

NNdef

.enKr

.enKrUni

.enAr

.enArUni

.enTr

Perform Side-Effects

When doing proper FRP (i.e. using ENdef or NNdef) these methods should not be used.

.fire

Emit an event to all registered listeners. This will send an event into the event processing network.

.do

Run f every time a new event arrives.

Arguments:

f

A function

Returns:

Unit

.stopDoing

Stop running function f.

Arguments:

f

A function

Returns:

Unit

.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

.remove

Disconnects this EventStream from the parent EventStream (if it has a parent). If the EventStream 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.