# Signal

Summary
 Signal Functions map Applies a function f to the given input signal sink Applies the function on the given signal for the purpose of performing side effects. filter Filters a signal using the given predicate function. merge Merges streams of the same type together. mergeMany Merges multiple signals together. join Joins streams of two types together. toUnit Maps a signal of some type to a signal of units. foldP Creates a past dependent signal. dropRepeats Drop values that have been repeated on the given signal. latch Constantly emmits the value held in the latch. map2 Applys a mapping function to two signals. record Records values in a list as they come in through the incoming signal. constant Gives a signal holding a specific value. meta Performs a meta analysis on a signal, and outputs this result in a signal. unmeta The opposite of the meta function. 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. unzip Unzips two signals apart, so that the tuple on the incoming signal is split into two signals. 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.

### map

Applies a function f to the given input signal

#### Type signature

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

#### Parameters

 f : (‘a) -> ‘b The 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) -> unit The function to call s : sig<’a> The input signal

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) -> bool The 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;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) -> ‘state The folding function state0 : ‘state ref A 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> ref A 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 ref Holds 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) -> ‘c The mapping function incomingA : sig<’a> The first signal incomingB : sig<’b> The second signal state : (‘a * ‘b) ref Holds 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> ref Previous 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 : ‘a The 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> 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) ref The state holding the past values of the signals

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 : ‘a The first value to toggle between val2 : ‘a The second value to toggle between state : ‘a ref Holds 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.