Module

FRP.Event

Package
purescript-hyrule
Repository
mikesol/purescript-hyrule

#fix Source

fix :: forall i. (Event i -> Event i) -> Event i

Compute a fixed point

#keepLatest Source

keepLatest :: forall a. Event (Event a) -> Event a

Flatten a nested Event, reporting values only from the most recent inner Event.

#sampleOnRight Source

sampleOnRight :: forall a b. 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.

#Event Source

newtype 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

#EventIO Source

type EventIO a = { event :: Event a, push :: a -> Effect Unit }

#EventIO' Source

type EventIO' a = { event :: Event a, push :: EffectFn1 a Unit }

#PureEventIO Source

type PureEventIO :: Region -> Type -> Typetype PureEventIO r a = { event :: Event a, push :: a -> ST r Unit }

#PureEventIO' Source

type PureEventIO' :: Region -> Type -> Typetype PureEventIO' r a = { event :: Event a, push :: STFn1 a r Unit }

#Subscriber Source

newtype Subscriber

Constructors

#bindToEffect Source

bindToEffect :: forall a b. Event a -> (a -> Effect b) -> Event b

#bindToST Source

bindToST :: forall a b. Event a -> (a -> ST Global b) -> Event b

#create Source

create :: forall a. ST Global (EventIO a)

Create an event and a function which supplies a value to that event.

#createO Source

createO :: forall a. ST Global (EventIO' a)

#createPure Source

createPure :: forall a r. ST r (PureEventIO r a)

Create an event and a function which supplies a value to that event in ST.

#createPureO Source

#delay Source

delay :: forall a. Int -> Event a -> Event (Either TimeoutId (Tuple (Maybe TimeoutId) a))

#delay_ Source

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

#foldE Source

foldE :: forall a b. (a -> b -> Effect a) -> a -> Event b -> Event a

#foldST Source

foldST :: forall a b. (a -> b -> ST Global a) -> a -> Event b -> Event a

#mailbox Source

mailbox :: forall a b. Ord a => ST Global { event :: a -> Event b, push :: { address :: a, payload :: b } -> Effect Unit }

#mailbox' Source

mailbox' :: forall a b. Ord a => ST Global { event :: a -> Event b, push :: EffectFn1 { address :: a, payload :: b } Unit }

#mailboxPure Source

mailboxPure :: forall a b. Ord a => ST Global { event :: a -> Event b, push :: { address :: a, payload :: b } -> ST Global Unit }

#mailboxPure' Source

mailboxPure' :: forall a b. Ord a => ST Global { event :: a -> Event b, push :: STFn1 { address :: a, payload :: b } Global Unit }

#mailboxed Source

mailboxed :: forall r a b. Ord a => Event { address :: a, payload :: b } -> ((a -> Event b) -> r) -> Event r

#makeEvent Source

makeEvent :: forall a. ((a -> Effect Unit) -> ST Global (ST Global Unit)) -> Event a

Make an Event from a function which accepts a callback and returns an unsubscription function.

Note: you probably want to use create instead, unless you need explicit control over unsubscription.

#makeEventE Source

makeEventE :: forall a. ((a -> Effect Unit) -> Effect (Effect Unit)) -> Effect { event :: Event a, unsubscribe :: Effect Unit }

#makeEventO Source

#makeLemmingEvent Source

makeLemmingEvent :: forall a. ((forall b. Event b -> (b -> ST Global Unit) -> ST Global (ST Global Unit)) -> (a -> ST Global Unit) -> ST Global (ST Global Unit)) -> Event a

#makeLemmingEventO Source

#makePureEvent Source

makePureEvent :: forall a. ((a -> ST Global Unit) -> ST Global (ST Global Unit)) -> Event a

Make a pure Event from a function which accepts a callback and returns an unsubscription function.

Note: you probably want to use create instead, unless you need explicit control over unsubscription.

#memoize Source

memoize :: forall a. Event a -> ST Global { event :: Event a, unsubscribe :: ST Global Unit }

#memoized Source

memoized :: forall r a. Event a -> (Event a -> r) -> Event r

#merge Source

merge :: forall a. Array (Event a) -> Event a

Merge together several events. This has the same functionality as oneOf, but it is faster and less prone to stack explosions.

#mergeMap Source

mergeMap :: forall a b. (a -> Event b) -> Array a -> Event b

Merge together several events and map on the event. This has the same functionality as oneOf, but it is faster and less prone to stack explosions.

#subscribe Source

subscribe :: forall a. Event a -> (a -> Effect Unit) -> ST Global (ST Global Unit)

Subscribe to an Event by providing a callback.

subscribe returns a canceller function.

#subscribeO Source

subscribeO :: forall a. STFn2 (Event a) (EffectFn1 a Unit) Global (ST Global Unit)

Subscribe to an Event by providing a callback.

subscribe returns a canceller function.

#subscribePure Source

subscribePure :: forall a. Event a -> (a -> ST Global Unit) -> ST Global (ST Global Unit)

#subscribePureO Source

#thankTheDriver Source

thankTheDriver :: forall a. Event (Tuple (Effect Unit) a) -> Event a

Re-exports from FRP.Event.Class

#Filterable Source

class Filterable :: (Type -> Type) -> Constraintclass (Compactable f, Functor f) <= Filterable f  where

Filterable represents data structures which can be partitioned/filtered.

  • partitionMap - partition a data structure based on an either predicate.
  • partition - partition a data structure based on boolean predicate.
  • filterMap - map over a data structure and filter based on a maybe.
  • filter - filter a data structure based on a boolean.

Laws:

  • Functor Relation: filterMap identity ≡ compact

  • Functor Identity: filterMap Just ≡ identity

  • Kleisli Composition: filterMap (l <=< r) ≡ filterMap l <<< filterMap r

  • filter ≡ filterMap <<< maybeBool

  • filterMap p ≡ filter (isJust <<< p)

  • Functor Relation: partitionMap identity ≡ separate

  • Functor Identity 1: _.right <<< partitionMap Right ≡ identity

  • Functor Identity 2: _.left <<< partitionMap Left ≡ identity

  • f <<< partition ≡ partitionMap <<< eitherBool where f = \{ no, yes } -> { left: no, right: yes }

  • f <<< partitionMap p ≡ partition (isRight <<< p) where f = \{ left, right } -> { no: left, yes: right}

Default implementations are provided by the following functions:

  • partitionDefault
  • partitionDefaultFilter
  • partitionDefaultFilterMap
  • partitionMapDefault
  • filterDefault
  • filterDefaultPartition
  • filterDefaultPartitionMap
  • filterMapDefault

Members

Instances

#IsEvent Source

class IsEvent :: (Type -> Type) -> Constraintclass (Plus event, Alt event, Filterable event) <= IsEvent event  where

Functions which an Event type should implement:

  • once: emits an event once
  • keepLatest flattens a nested event, reporting values only from the most recent inner event.
  • sampleOnRight: samples an event at the times when a second event fires.
  • fix: compute a fixed point, by feeding output events back in as inputs.

Members

  • keepLatest :: forall a. event (event a) -> event a
  • sampleOnRight :: forall a b. event a -> event (a -> b) -> event b
  • fix :: forall i. (event i -> event i) -> event i

#withLast Source

withLast :: forall event a. IsEvent event => event a -> event { last :: Maybe a, now :: a }

Compute differences between successive event values.

#sampleOnRight_ Source

sampleOnRight_ :: forall event a b. IsEvent event => 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.

#mapAccum Source

mapAccum :: forall event a b c. IsEvent event => (a -> b -> Tuple a c) -> a -> event b -> event c

Map over an event with an accumulator.

For example, to keep the index of the current event:

mapAccum (\x i -> Tuple (i + 1) (Tuple x i)) 0`.

#gateBy Source

gateBy :: forall a b event. IsEvent event => (Maybe a -> b -> Boolean) -> event a -> event b -> event b

Generalised form of gateBy, allowing for any predicate between the two events. The predicate will not be evaluated until a value from the first event is received.

#gate Source

gate :: forall a event. IsEvent event => event Boolean -> event a -> event a

Sample the events that are fired while a boolean event is true. Note that, until the boolean event fires, it will be assumed to be false, and events will be blocked.

#folded Source

folded :: forall event a. IsEvent event => Monoid a => event a -> event a

Combine subsequent events using a Monoid.

#fold Source

fold :: forall event a b. IsEvent event => (b -> a -> b) -> b -> event a -> event b

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

#count Source

count :: forall event a. IsEvent event => event a -> event Int

Count the number of events received.