# Module `Note.E`

Events.

An event is a value with discrete occurences over time.

## Events

`type 'a t`

`= 'a event`

The type for events with occurences of type

`'a`

.

`type 'a send`

`= ?step:Step.t -> 'a -> unit`

The type for functions sending event occurences of type

`'a`

. See`create`

.

`val log : ?now:bool -> 'a event -> ('a -> unit) -> Logr.t option`

`log ?now e f`

is`Some (Logr.(create ?now (const f $ obs e)))`

if`e`

is not`never`

and`None`

otherwise.

`val create : unit -> 'a event * 'a send`

`create ()`

is a primitive event`e`

and a`send`

function. The function`send`

is such that:`send v`

generates an occurence`v`

of`e`

at the time it is called .`send ~step v`

generates an occurence`v`

of`e`

at the time`step`

. The function should not be called again before`step`

is executed.

**Warning.**`send`

must not be used in the definition of signals or events.

`val value : 'a event -> 'a option`

`value e`

is the value of event`e`

at call time. If this is`None`

the event has no occurence, if this is`Some v`

, the event occurs with`v`

.

`val never : 'a event`

`never`

is a never occuring event, [`never`

]_{t}`= None`

.

`val bind : 'a event -> ('a -> 'b event) -> 'b event`

`bind e f`

is the event that results from applying`f`

to the last event of`e`

:- [
`bind e f`

]_{t}`=`

[`f v`

]_{t}if [`e`

]_{<=t}`= Some v`

. - [
`bind e f`

]_{t}`=`

`never`

if [`e`

]_{<=t}`= None`

.

- [

`val swap : 'a event signal -> 'a event`

`swap es`

is the current event of`es`

, [`swap es`

]_{t}`=`

[[`es`

]_{t}]_{t}.

`val map : ('a -> 'b) -> 'a event -> 'b event`

`map f e`

applies`f`

to`e`

's occurrences.- [
`map f e`

]_{t}`= Some (f v)`

if [`e`

]_{t}`= Some v`

. - [
`map f e`

]_{t}`= None`

otherwise.

- [

`val filter : ('a -> bool) -> 'a event -> 'a event`

`filter p e`

are the occurences of`e`

that satisfy`p`

.- [
`filter p e`

]_{t}`= Some v`

if [`e`

]_{t}`= Some v`

and`p v = true`

- [
`filter p e`

]_{t}`= None`

otherwise.

- [

`val filter_map : ('a -> 'b option) -> 'a event -> 'b event`

`filter_map fm e`

are`e`

's occurrences filtered and mapped by`fm`

.- [
`filter_map fm e`

]_{t}`= Some v`

if`fm`

[`e`

]_{t}`= Some v`

- [
`filter_map fm e`

]_{t}`= None`

otherwise.

- [

`val select : 'a event list -> 'a event`

`select el`

is the occurences of every event in`el`

. If more than one event occurs simlutanously, the leftmost is taken and the other are lost:- [
`select el`

]_{t}`=`

[`List.find (fun e ->`

[`e`

]_{t}`<> None) el`

]_{t}. - [
`select el`

]_{t}`= None`

otherwise.

- [

`val accum : 'a -> ('a -> 'a) event -> 'a event`

`accum i e`

accumulates a value, starting with`i`

, using`e`

's functional occurrences.- [
`accum i e`

]_{t}`= Some (f i)`

if [`e`

]_{t}`= Some f`

and [`e`

]_{<t}`= None`

. - [
`accum i e`

]_{t}`= Some (f acc)`

if [`e`

]_{t}`= Some f`

and [`accum i e`

]_{<t}`= Some acc`

. - [
`accum i e`

]`= None`

otherwise.

- [

`val until : ?limit:bool -> next:'a event -> 'b event -> 'b event`

`until ~limit ~next e`

is`e`

's occurences until`next`

occurs. At that point if`e`

occurs simultaneously the occurence is discarded (`limit`

is`false`

, default) or kept (`limit`

is`true`

) and after this the event never occurs again.- [
`until ~limit ~next e`

]_{t}`=`

[`e`

]_{t}if [`next`

]_{<=t}`= None`

- [
`until ~limit:false ~next e`

]_{t}`= None`

if [`next`

]_{t}`= Some _`

and [`next`

]_{<t}`= None`

. - [
`until ~limit:true ~next e`

]_{t}`=`

[`e`

]_{t}if [`next`

]_{t}`= Some _`

and [`next`

]_{<t}`= None`

. - [
`until ~limit ~next e`

]_{t}`= None`

otherwise.

- [

`val follow : 'a event -> on:bool signal -> 'a event`

`follow e ~on`

is`e`

's occurences whenever`on`

is`true`

.- [
`follow e ~on`

]_{t}`=`

[`e`

]_{t}if [`on`

]_{t}`= true`

- [
`follow e ~on`

]_{t}`= None`

if [`on`

]_{t}`= false`

- [

`val defer : 'a event -> 'a event`

`defer s`

is`s`

delayed by an infinitesimal amount of time. At creation time`init`

is used (defaults to`S.value s`

).- [
`defer e`

]_{t}`=`

`None`

for t = 0. - [
`defer e`

]_{t}`=`

[`e`

]_{t-dt}otherwise.

- [

`val fix : ('a event -> 'a event * 'b) -> 'b`

`fix ef`

allows to refer to the value an event had an infinitesimal amount of time before.In

`fix ef`

,`ef`

is called with an event`e`

that represents the event returned by`ef`

delayed by an infinitesimal amount of time. If`e', r = ef e`

then`r`

is returned by`fix`

and`e`

is such that :- [
`e`

]_{t}`=`

`None`

if t = 0 - [
`e`

]_{t}`=`

[`e'`

]_{t-dt}otherwise

**Raises.**`Invalid_argument`

if`e'`

is directly a delayed event (i.e. an event given to a fixing function).- [

## Stdlib types support

`module Option : sig ... end`

Option events

`module Pair : sig ... end`

Pair events.