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
. Seecreate
.
val log : ?now:bool -> 'a event -> ('a -> unit) -> Logr.t option
log ?now e f
isSome (Logr.(create ?now (const f $ obs e)))
ife
is notnever
andNone
otherwise.
val create : unit -> 'a event * 'a send
create ()
is a primitive evente
and asend
function. The functionsend
is such that:send v
generates an occurencev
ofe
at the time it is called .send ~step v
generates an occurencev
ofe
at the timestep
. The function should not be called again beforestep
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 evente
at call time. If this isNone
the event has no occurence, if this isSome v
, the event occurs withv
.
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 applyingf
to the last event ofe
:- [
bind e f
]t=
[f v
]t if [e
]<=t= Some v
. - [
bind e f
]t=
never
if [e
]<=t= None
.
- [
val map : ('a -> 'b) -> 'a event -> 'b event
map f e
appliesf
toe
'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 ofe
that satisfyp
.- [
filter p e
]t= Some v
if [e
]t= Some v
andp v = true
- [
filter p e
]t= None
otherwise.
- [
val filter_map : ('a -> 'b option) -> 'a event -> 'b event
filter_map fm e
aree
's occurrences filtered and mapped byfm
.- [
filter_map fm e
]t= Some v
iffm
[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 inel
. 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 withi
, usinge
'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
ise
's occurences untilnext
occurs. At that point ife
occurs simultaneously the occurence is discarded (limit
isfalse
, default) or kept (limit
istrue
) 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
ise
's occurences wheneveron
istrue
.- [
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
iss
delayed by an infinitesimal amount of time. At creation timeinit
is used (defaults toS.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 evente
that represents the event returned byef
delayed by an infinitesimal amount of time. Ife', r = ef e
thenr
is returned byfix
ande
is such that :- [
e
]t=
None
if t = 0 - [
e
]t=
[e'
]t-dt otherwise
Raises.
Invalid_argument
ife'
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.