Signal

Summary
Signal
Functions
mapApplies a function f to the given input signal
sinkApplies the function on the given signal for the purpose of performing side effects.
filterFilters a signal using the given predicate function.
mergeMerges streams of the same type together.
mergeManyMerges multiple signals together.
joinJoins streams of two types together.
toUnitMaps a signal of some type to a signal of units.
foldPCreates a past dependent signal.
dropRepeatsDrop values that have been repeated on the given signal.
latchConstantly emmits the value held in the latch.
map2Applys a mapping function to two signals.
recordRecords values in a list as they come in through the incoming signal.
constantGives a signal holding a specific value.
metaPerforms a meta analysis on a signal, and outputs this result in a signal.
unmetaThe opposite of the meta function.
zipZips two signals together, so that if a value is received on either signal, then the output signal will also contain the latest value from the other signal.
unzipUnzips two signals apart, so that the tuple on the incoming signal is split into two signals.
toggleIf a value is carried on the incoming signal, then the output signal holds a value of val2 if the value stored in state is equal to val1; otherwise, the output signal holds a value of val1.

Functions

map

Applies a function f to the given input signal

Type signature

<'a,'b>(('a) -> 'b, sig<'a>) -> sig<'b>

Parameters

f : (‘a) -> ‘bThe mapping function
s : sig<’a>The input signal

Returns

The signal transformed by the mapping function

sink

Applies the function on the given signal for the purpose of performing side effects.

Type signature

<'a>(('a) -> unit, sig<'a>) -> unit

Parameters

f : (‘a) -> unitThe function to call
s : sig<’a>The input signal

Returns

Unit

filter

Filters a signal using the given predicate function.  If the function returns true, the signal is filtered and the output signal will contain nothing.  If the function returns false, the signal is unfiltered and the output signal will be the same as the input signal.

Type signature

<'a>(('a') -> bool, sig<'a>) -> sig<'a>

Parameters

f : (‘a) -> boolThe predicate function
s : sig<’a>The input signal

Returns

The filtered output signal.

merge

Merges streams of the same type together.  If sigA has a value, then sigA is returned.  Otherwise sigB is returned.

Type signature

merge<'a>(sig<'a>, sig<'a>) -> sig<'a>

Parameters

sigA : sig<’a>The first signal to merge
sigB : sig<’b>The second signal to merge

Returns

A signal of the two merged streams

mergeMany

Merges multiple signals together.  The leftmost stream holding a value is the value held by the return signal.  If none of the given signals holds a value, then the return stream will hold nothing.

Type signature

<'a;n>(list<sig<'a>;n>) -> sig<'a>

Parameters

sigs : list<sig<’a>;n>A list of signals to merge together.

join

Joins streams of two types together.  If sigA has a value, then Prelude:left is used to construct the output signal.  Otherwise if sigB has a value then Prelude:right is used to construct the output signal.  If neither sigA or sigB holds a value, then the output signal also holds no value.

Type signature

<'a,'b>(sig<'a>, sig<'b>) -> sig<either<'a,'b>>

Parameters

sigA : sig<’a>The first signal to join
sigB : sig<’b>The second signal to join

Returns

A signal of the two joined streams.

toUnit

Maps a signal of some type to a signal of units.  If sig holds a value, then the output signal holds unit.  Otherwise the output signal holds nothing.

Type signature

<'a>(sig<'a>) -> sig<unit>

Parameters

s : sig<’a>The signal to convert to a unit signal

Returns

A signal of units.

foldP

Creates a past dependent signal.  If the incoming signal contains a value, f will be called on the value and the previous state and the return value from this function determines the new state.  The state is held in a reference. foldP stands for fold over the past.

Type signature

foldP<'a,'state>(('a,'state)->'state, 'state ref, sig<'a>) -> sig<'state>

Parameters

f : (‘a,’state) -> ‘stateThe folding function
state0 : ‘state refA reference to the mutable state
incoming : sig<’a>The signal of incoming values

Returns

A signal containing the state just returned by f, or nothing if the input signal contained nothing.

dropRepeats

Drop values that have been repeated on the given signal.

Type signature

<'a>(sig<'a>, maybe<'a> ref) -> sig<'a>

Parameters

incoming : sig<’a>The incoming signal
maybePrevValue : maybe<’a> refA reference holding the previous value or none if there hasn’t been a previous value yet

Returns

A filtered signal where two values in a row will not be repeated.

latch

Constantly emmits the value held in the latch.  The value held in the latch is updated if it receives a value on the incoming signal.

Type Signature

<'a>(sig<'a>, 'a ref) -> sig<'a>

Parameters

incoming : sig<’a>The incoming latch update signal
prevValue : ‘a refHolds the previous values that the latch received

Returns

A signal which constantly emmits the value last received on the incoming signal.

map2

Applys a mapping function to two signals.  The function is evaluated when a value arrives on either signal.  If no value is held by either of the input signals, then the output signal holds no value.

Type Signature

<'a,'b,'c>(('a,'b)->'c, sig<'a>, sig<'b>, ('a*'b) ref) -> sig<'c>

Parameters

f : (‘a,’b) -> ‘cThe mapping function
incomingA : sig<’a>The first signal
incomingB : sig<’b>The second signal
state : (‘a * ‘b) refHolds the last values received from the signals.

Returns

The mapped signal

record

Records values in a list as they come in through the incoming signal.

Type Signature

<'a;n>(sig<'a>, list<'a;n> ref) -> sig<list<'a;n>>

Parameters

incoming : sig<’a>Incoming values to record
pastValues : list<’a;n> refPrevious values recorded from the signal

Returns

A signal holding the list of previous values

constant

Gives a signal holding a specific value.

Type Signature

<'a>('a) -> sig<'a>

Parameters

val : ‘aThe value that will be held within the signal

Returns

A signal containing the given value

meta

Performs a meta analysis on a signal, and outputs this result in a signal.  The output signal will hold a value of nothing when there is no value on the input signal, and will return just the value if there is a value on the input signal.  The output signal will always hold a value, which makes it useful for many applications.

Type Signature

<'a>(sig<'a>) -> sig<maybe<'a>>

Parameters

sigA : sig<’a>The signal on which the meta analysis will be performed

Returns

A signal of either nothing or just the value of the input signal

unmeta

The opposite of the meta function.  If the input signal holds a value of nothing, then the output signal will not hold a value.  If the input signal holds just a value, then the output signal will hold that value.

Type Signature

<'a>(sig<maybe<'a>>) -> sig<'a>

Parameters

sigA : sig<maybe<’a>>The signal to “make concrete”

Returns

A signal that holds a value in the case of the input signal holding just a value, and holds no value otherwise.

zip

Zips two signals together, so that if a value is received on either signal, then the output signal will also contain the latest value from the other signal.  If no value is held by either of the input signals, then the output signal holds no value.

Type Signature

<'a,'b>(sig<'a>, sig<'b>, ('a * 'b) ref) -> sig<'a * 'b>

Parameters

sigA : sig<’a>The first signal to zip
sigB : sig<’b>The second signal to zip
state : (‘a * ‘b) refThe state holding the past values of the signals

Returns

A zipped signal.

unzip

Unzips two signals apart, so that the tuple on the incoming signal is split into two signals.

Type Signature

<'a,'b>(sig<'a * 'b>) -> (sig<'a> * sig<'b>)

Parameters

incoming : sig<’a>The signal to unzip

Returns

Two signals inside a tuple

toggle

If a value is carried on the incoming signal, then the output signal holds a value of val2 if the value stored in state is equal to val1; otherwise, the output signal holds a value of val1.  If no value is carried on the incoming signal, then no value is outputted on the return signal.

Type Signature

<'a,'b>('a, 'a, 'a ref, sig<'b>) -> sig<'a>

Parameters

val1 : ‘aThe first value to toggle between
val2 : ‘aThe second value to toggle between
state : ‘a refHolds the previous value outputted on the return signal
incoming : sig<’b>The signal which will trigger a toggle

Returns

A signal containing either val1 or val2, depending on what was previously value carried on the output signal.

Close