Module

FRP.Event.Class

Package
purescript-hyrule
Repository
mikesol/purescript-hyrule

#IsEvent Source

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

Functions which an Event type should implement:

  • fold: combines incoming values using the specified function, starting with the specific initial value.
  • keepLatest flattens a nested event, reporting values only from the most recent inner event.
  • sampleOn: samples an event at the times when a second event fires.
  • fix: compute a fixed point, by feeding output events back in as inputs.
  • bang: A one-shot event that happens NOW.

Members

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

#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.

#folded Source

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

Combine subsequent events using a Monoid.

#count Source

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

Count the number of events received.

#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`.

#withLast Source

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

Compute differences between successive event values.

#(<|**>) Source

Operator alias for FRP.Event.Class.sampleOnRight (left-associative / precedence 4)

#sampleOnRightOp Source

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

#(<|*>) Source

Operator alias for FRP.Event.Class.sampleOnRightOp (left-associative / precedence 4)

#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.

#(<|*) Source

Operator alias for FRP.Event.Class.sampleOnRight_ (left-associative / precedence 4)

#(<**|>) Source

Operator alias for FRP.Event.Class.sampleOnLeft (left-associative / precedence 4)

#sampleOnLeftOp Source

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

#(<*|>) Source

Operator alias for FRP.Event.Class.sampleOnLeftOp (left-associative / precedence 4)

#sampleOnLeft_ Source

sampleOnLeft_ :: forall event a b. IsEvent event => event a -> event b -> event b

#(*|>) Source

Operator alias for FRP.Event.Class.sampleOnLeft_ (left-associative / precedence 4)

#applyOp Source

applyOp :: forall event a b. Applicative event => event a -> event (a -> b) -> event b

#(<**>) Source

Operator alias for FRP.Event.Class.applyOp (left-associative / precedence 4)

#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.

#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.

Re-exports from Data.Filterable

#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