Data.Hareactive
- Package
- purescript-hareactive
- Repository
- funkia/purescript-hareactive
#Now Source
data Now :: Type -> Type
A Now
represents a computation that occurs at a specific moment in time.
That moment is always "now". This means that computations inside the now
can depend on time—but only the current point in time. The requirement
that Time
is always the current moment in time is enforced and
guaranteed by the API for working with time.
In addition to containing time-dependent computations a Now
can also
contain computations with side-effects. An approximate model of a Now a
is that it is equivalent to Time -> IO a
.
Now
servers two purposes in Hareactive: It makes it possible to create
stateful behaviors that depends on the past without introducing
space-leaks (a notorious problem in FRP). Additionally, it is the glue
between FRP primitives and effectful computations.
Instances
#Behavior Source
data Behavior :: Type -> Type
A behavior represents a value that changes over time. I.e. a value that
depends on time. Semantically a Behavior a
can be understood as being
equivalent to a function Time -> a
. A behavior isn't implemented as a
function. But the semantics serve as a mental model in terms of which all
other operations can be understood.
Instances
#Stream Source
data Stream :: Type -> Type
A stream represents events that occur at specific moments in time. It is a
list of future values. Semantically a Stream a
can be understood as
List (Time, a)
. That is, a list of values where each value is associated
with a specific moment in time. The time values have to be increasing.
But, they do not have to be strictly increasing. This means that a
stream can have several occurrences at the same moment in time. This can
be very useful in certain circumstances.
Instances
#Future Source
data Future :: Type -> Type
A future is a value associated with some point in time. Semantically a
Future a
is equivalent to (Time, a)
. That is, a value tagged with
time. In practice, Stream
is used more often than Future
. Future
is
useful in circumstances where some event occurs exactly once in the
future.
Instances
#filterApply Source
filterApply :: forall a. Behavior (a -> Boolean) -> Stream a -> Stream a
A combination of filter
and apply
#snapshotWith Source
snapshotWith :: forall c b a. (a -> b -> c) -> Behavior b -> Stream a -> Stream c
Returns a stream that occurs whenever the given stream occurs. At each occurrence the value and the value from the behavior is passed to the function and the return value is the value of the returned streams occurrence.
- Modules
- Data.
Hareactive
The
Semigroup
instance merges to streams by combining their occurrences while keeping them ordered with respect to time.One detail to be aware of is what happens in case both the left and the right stream contains occurences that occur simultaneously. The
sortWith
in the semantics below is stable. This implies that simultaneous ocurrences in the left stream will occurr before ones in the righ stream.Semantically.