Primitive and basics
type 'a t = 'a eventThe type for events with occurrences of type 'a.
val never : 'a eventA never occuring event. For all t, [never]t = None.
create () is a primitive event e and a send function. The function send is such that:
send vgenerates an occurrencevofeat the time it is called and triggers an update step.send ~step vgenerates an occurencevofeon the stepstepwhenstepis executed.send ~step vraisesInvalid_argumentif it was previously called with a step and this step has not executed yet or if the givenstepwas already executed.
Warning. send must not be executed inside an update step.
val retain : 'a event -> (unit -> unit) -> [ `R of unit -> unit ]retain e c keeps a reference to the closure c in e and returns the previously retained value. c will never be invoked.
Raises. Invalid_argument on E.never.
val stop : ?strong:bool -> 'a event -> unitstop e stops e from occuring. It conceptually becomes never and cannot be restarted. Allows to disable effectful events.
The strong argument should only be used on platforms where weak arrays have a strong semantics (i.e. JavaScript). See details.
Note. If executed in an update step the event may still occur in the step.
equal e e' is true iff e and e' are equal. If both events are different from never, physical equality is used.
trace iff tr e is e except tr is invoked with e's occurence when iff is true (defaults to S.const true). For all t where [e]t = Some v and [iff]t = true, tr is invoked with v.
Transforming and filtering
once e is e with only its next occurence.
- [
once e]t= Some vif [e]t= Some vand [e]<t= None. - [
once e]t= Noneotherwise.
drop_once e is e without its next occurrence.
- [
drop_once e]t= Some vif [e]t= Some vand [e]<t= Some _. - [
drop_once e]t= Noneotherwise.
app ef e occurs when both ef and e occur simultaneously. The value is ef's occurence applied to e's one.
- [
app ef e]t= Some v'if [ef]t= Some fand [e]t= Some vandf v = v'. - [
app ef e]t= Noneotherwise.
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= Noneotherwise.
filter p e are e's occurrences that satisfy p.
- [
filter p e]t= Some vif [e]t= Some vandp v = true - [
filter p e]t= Noneotherwise.
fmap fm e are e's occurrences filtered and mapped by fm.
- [
fmap fm e]t= Some viffm[e]t= Some v - [
fmap fm e]t= Noneotherwise.
diff f e occurs whenever e occurs except on the next occurence. Occurences are f v v' where v is e's current occurrence and v' the previous one.
- [
diff f e]t= Some rif [e]t= Some v, [e]<t= Some v'andf v v' = r. - [
diff f e]t= Noneotherwise.
changes eq e is e's occurrences with occurences equal to the previous one dropped. Equality is tested with eq (defaults to structural equality).
- [
changes eq e]t= Some vif [e]t= Some vand either [e]<t= Noneor [e]<t= Some v'andeq v v' = false. - [
changes eq e]t= Noneotherwise.
on c e is the occurrences of e when c is true.
- [
on c e]t= Some vif [c]t= trueand [e]t= Some v. - [
on c e]t= Noneotherwise.
dismiss c e is the occurences of e except the ones when c occurs.
- [
dimiss c e]t= Some vif [c]t= Noneand [e]t= Some v. - [
dimiss c e]t= Noneotherwise.
until c e is e's occurences until c occurs.
- [
until c e]t= Some vif [e]t= Some vand [c]<=t= None - [
until c e]t= Noneotherwise.
Accumulating
accum ef i accumulates a value, starting with i, using e's functional occurrences.
- [
accum ef i]t= Some (f i)if [ef]t= Some fand [ef]<t= None. - [
accum ef i]t= Some (f acc)if [ef]t= Some fand [accum ef i]<t= Some acc. - [
accum ef i]= Noneotherwise.
fold f i e accumulates e's occurrences with f starting with i.
- [
fold f i e]t= Some (f i v)if [e]t= Some vand [e]<t= None. - [
fold f i e]t= Some (f acc v)if [e]t= Some vand [fold f i e]<t= Some acc. - [
fold f i e]t= Noneotherwise.
Combining
select el is the occurrences of every event in el. If more than one event occurs simultaneously the leftmost is taken and the others are lost.
- [
select el]t=[List.find (fun e ->[e]t<> None) el]t. - [
select el]t= Noneotherwise.
merge f a el merges the simultaneous occurrences of every event in el using f and the accumulator a.
[merge f a el]t = List.fold_left f a (List.filter (fun o -> o <> None)
(List.map []t el)).
switch e ee is e's occurrences until there is an occurrence e' on ee, the occurrences of e' are then used until there is a new occurrence on ee, etc..
- [
switch e ee]t=[e]t if [ee]<=t= None. - [
switch e ee]t=[e']t if [ee]<=t= Some e'.
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=Noneif 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).
Lifting
val l5 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> 'a event -> 'b event -> 'c event -> 'd event -> 'e event -> 'f eventval l6 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) -> 'a event -> 'b event -> 'c event -> 'd event -> 'e event -> 'f event -> 'g eventPervasives support
module Option : sig ... endEvents with option occurences.