Module React.E
Event combinators.
Consult their semantics.
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.
val create : unit -> 'a event * (?step:step -> 'a -> unit)create ()is a primitive eventeand asendfunction. The functionsendis 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.
sendmust not be executed inside an update step.
val retain : 'a event -> (unit -> unit) -> [ `R of unit -> unit ]retain e ckeeps a reference to the closurecineand returns the previously retained value.cwill never be invoked.Raises.
Invalid_argumentonE.never.
val stop : ?strong:bool -> 'a event -> unitstop estopsefrom occuring. It conceptually becomesneverand cannot be restarted. Allows to disable effectful events.The
strongargument 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.
Transforming and filtering
val once : 'a event -> 'a eventonce eisewith only its next occurence.- [
once e]t= Some vif [e]t= Some vand [e]<t= None. - [
once e]t= Noneotherwise.
- [
val drop_once : 'a event -> 'a eventdrop_once eisewithout its next occurrence.- [
drop_once e]t= Some vif [e]t= Some vand [e]<t= Some _. - [
drop_once e]t= Noneotherwise.
- [
val app : ('a -> 'b) event -> 'a event -> 'b eventapp ef eoccurs when bothefandeoccur simultaneously. The value isef's occurence applied toe's one.- [
app ef e]t= Some v'if [ef]t= Some fand [e]t= Some vandf v = v'. - [
app ef e]t= Noneotherwise.
- [
val map : ('a -> 'b) -> 'a event -> 'b eventmap f eappliesftoe's occurrences.- [
map f e]t= Some (f v)if [e]t= Some v. - [
map f e]t= Noneotherwise.
- [
val filter : ('a -> bool) -> 'a event -> 'a eventfilter p earee's occurrences that satisfyp.- [
filter p e]t= Some vif [e]t= Some vandp v = true - [
filter p e]t= Noneotherwise.
- [
val fmap : ('a -> 'b option) -> 'a event -> 'b eventfmap fm earee's occurrences filtered and mapped byfm.- [
fmap fm e]t= Some viffm[e]t= Some v - [
fmap fm e]t= Noneotherwise.
- [
val diff : ('a -> 'a -> 'b) -> 'a event -> 'b eventdiff f eoccurs whenevereoccurs except on the next occurence. Occurences aref v v'wherevise's current occurrence andv'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.
- [
val changes : ?eq:('a -> 'a -> bool) -> 'a event -> 'a eventchanges eq eise's occurrences with occurences equal to the previous one dropped. Equality is tested witheq(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.
- [
val on : bool signal -> 'a event -> 'a eventon c eis the occurrences ofewhencistrue.- [
on c e]t= Some vif [c]t= trueand [e]t= Some v. - [
on c e]t= Noneotherwise.
- [
Accumulating
Combining
val select : 'a event list -> 'a eventselect elis the occurrences of every event inel. 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.
- [
val merge : ('a -> 'b -> 'a) -> 'a -> 'b event list -> 'a eventmerge f a elmerges the simultaneous occurrences of every event inelusingfand the accumulatora.[
merge f a el]t= List.fold_left f a (List.filter (fun o -> o <> None) (List.map[]tel)).
val switch : 'a event -> 'a event event -> 'a eventswitch e eeise's occurrences until there is an occurrencee'onee, the occurrences ofe'are then used until there is a new occurrence onee, etc..- [
switch e ee]t=[e]t if [ee]<=t= None. - [
switch e ee]t=[e']t if [ee]<=t= Some e'.
- [
val fix : ('a event -> 'a event * 'b) -> 'bfix efallows to refer to the value an event had an infinitesimal amount of time before.In
fix ef,efis called with an eventethat represents the event returned byefdelayed by an infinitesimal amount of time. Ife', r = ef ethenris returned byfixandeis such that :- [
e]t=Noneif t = 0 - [
e]t=[e']t-dt otherwise
Raises.
Invalid_argumentife'is directly a delayed event (i.e. an event given to a fixing function).- [
Lifting
Lifting combinators. For a given n the semantics is:
- [
ln f e1 ... en]t= Some (f v1 ... vn)if for all i : [ei]t= Some vi. - [
ln f e1 ... en]t= Noneotherwise.
val l1 : ('a -> 'b) -> 'a event -> 'b eventval l2 : ('a -> 'b -> 'c) -> 'a event -> 'b event -> 'c eventval l3 : ('a -> 'b -> 'c -> 'd) -> 'a event -> 'b event -> 'c event -> 'd eventval l4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a event -> 'b event -> 'c event -> 'd event -> 'e eventval 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 event
Pervasives support
module Option : sig ... endEvents with option occurences.