Module

FRP.Event

Package
purescript-behaviors
Repository
paf31/purescript-behaviors

#Event Source

data Event a

An Event represents a collection of discrete occurrences with associated times. Conceptually, an Event is a (possibly-infinite) list of values-and-times:

type Event a = List { value :: a, time :: Time }

Events are created from real events like timers or mouse clicks, and then combined using the various functions and instances provided in this module.

Events are consumed by providing a callback using the subscribe function.

Instances

#never Source

never :: forall a. Event a

#fold Source

fold :: forall b a. (a -> b -> b) -> Event a -> b -> Event b

Fold over values received from some Event, creating a new Event.

#count Source

count :: forall a. Event a -> Event Int

Count the number of events received.

#folded Source

folded :: forall a. Monoid a => Event a -> Event a

Count the number of events received.

#withLast Source

withLast :: forall a. Event a -> Event { last :: Maybe a, now :: a }

Compute differences between successive event values.

#filter Source

filter :: forall a. (a -> Boolean) -> Event a -> Event a

Create an Event which only fires when a predicate holds.

#mapMaybe Source

mapMaybe :: forall b a. (a -> Maybe b) -> Event a -> Event b

Filter out any Nothing events.

#sampleOn Source

sampleOn :: forall b a. Event a -> Event (a -> b) -> Event b

Create an Event which samples the latest values from the first event at the times when the second event fires.

#sampleOn_ Source

sampleOn_ :: forall b a. Event a -> Event b -> Event a

Create an Event which samples the latest values from the first event at the times when the second event fires, ignoring the values produced by the second event.

#subscribe Source

subscribe :: forall r a eff. Event a -> (a -> Eff (frp :: FRP | eff) r) -> Eff (frp :: FRP | eff) Unit

Subscribe to an Event by providing a callback.