| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Data.Var
- data Sig a
- newSig :: Fay (Sig a)
- data Ref a
- newRef :: a -> Fay (Ref a)
- data Var a
- newVar :: a -> Fay (Var a)
- class Settable v
- set :: Settable (v a) => v a -> a -> Fay ()
- class Gettable v
- get :: Gettable (v a) => v a -> Fay a
- modify :: (Settable (v a), Gettable (v a)) => v a -> (a -> a) -> Fay ()
- modifyWith :: (Settable (v a), Gettable (v a)) => v a -> (a -> Fay a) -> Fay ()
- class Settable v => Subscribable v
- subscribe :: Subscribable (v a) => v a -> Ptr (a -> Fay void) -> Fay (() -> Fay ())
- withUnsubscriber :: ((a -> Fay ()) -> Fay (() -> Fay ())) -> ((() -> Fay ()) -> a -> Fay ()) -> Fay (() -> Fay ())
- subscribeWithOld :: Var a -> (a -> a -> Fay ()) -> Fay (() -> Fay ())
- subscribeChange :: Eq a => Var a -> (a -> Fay ()) -> Fay (() -> Fay ())
- subscribeAndRead :: Var a -> (a -> Fay void) -> Fay (() -> Fay ())
- subscribeChangeAndRead :: Eq a => Var a -> (a -> Fay ()) -> Fay (() -> Fay ())
- subscribeExclusive :: Subscribable (v a) => v a -> (a -> Fay ()) -> Fay (a -> Fay (), () -> Fay ())
- subscribeAndReadExclusive :: Var a -> (a -> Fay ()) -> Fay (a -> Fay (), () -> Fay ())
- mapVar :: (a -> b) -> Var a -> Fay (Var b)
- mergeVars :: (a -> b -> c) -> Maybe (c -> (a, b)) -> Var a -> Var b -> Fay (Var c, Fay ())
- mergeVars' :: (a -> b -> c) -> Maybe (c -> (a, b)) -> Var a -> Var b -> Fay (Var c)
- tupleVars :: Var a -> Var b -> Fay (Var (a, b), Fay ())
- tupleVars' :: Var a -> Var b -> Fay (Var (a, b))
- waitForN :: Int -> Fay (Fay void -> Fay (), Sig ())
- waitFor :: Var a -> (a -> Bool) -> (a -> Fay ()) -> Fay ()
- oneShot :: Subscribable (v a) => v a -> (a -> Fay ()) -> Fay ()
- holdSig :: a -> Sig a -> Fay (Var a)
Different types of variables
A subscribable signal. Can have handlers subscribed to them, but doesn't store a value.
Instances
| Subscribable (Sig a) | |
| Settable (Sig a) |
A mutable reference, with no subscribers.
A reactive variable. Stores a value, and can have handlers subscribed to changes.
Generic operations
All of the variable types can be set to a value.
set :: Settable (v a) => v a -> a -> Fay () Source
Write to the value (if any), and call subscribers (if any).
modify :: (Settable (v a), Gettable (v a)) => v a -> (a -> a) -> Fay () Source
Modifies the current value with a pure function.
modifyWith :: (Settable (v a), Gettable (v a)) => v a -> (a -> Fay a) -> Fay () Source
Runs a Fay action on the current value, and updates with the result.
class Settable v => Subscribable v Source
Instances
| Subscribable (Var a) | |
| Subscribable (Sig a) |
withUnsubscriber :: ((a -> Fay ()) -> Fay (() -> Fay ())) -> ((() -> Fay ()) -> a -> Fay ()) -> Fay (() -> Fay ()) Source
Run the same subscribing action but provide an additional unsubscribe parameter to the handler.
Specific operations
subscribeWithOld :: Var a -> (a -> a -> Fay ()) -> Fay (() -> Fay ()) Source
Subscribe to a Var, along with the previous value.
The result is an unsubscribe function.
subscribeChange :: Eq a => Var a -> (a -> Fay ()) -> Fay (() -> Fay ()) Source
Subscribe to a Var, but only call handler when it actually changes.
The result is an unsubscribe function.
subscribeAndRead :: Var a -> (a -> Fay void) -> Fay (() -> Fay ()) Source
Subscribe to a Var, and call the function on the current value.
The result is an unsubscribe function.
subscribeChangeAndRead :: Eq a => Var a -> (a -> Fay ()) -> Fay (() -> Fay ()) Source
Subscribe to a Var, but only call handler when it actually changes, and
also initially on registration.
The result is an unsubscribe function.
subscribeExclusive :: Subscribable (v a) => v a -> (a -> Fay ()) -> Fay (a -> Fay (), () -> Fay ()) Source
Given a change handler, returns a function that can be used to set a
subscribable without invoking the handler. This can be useful in
situations where the handler for a Var causes an event which otherwise
ought to set the value of the Var. An example of this is interfacing
with HTML input field change events.
The snd part of the result is an unsubscribe function.
subscribeAndReadExclusive :: Var a -> (a -> Fay ()) -> Fay (a -> Fay (), () -> Fay ()) Source
Given a change handler, returns a function that can be used to set a var
without invoking the handler. The handler is called with the initial
value. This can be useful in situations where the handler for a Var
causes an event which otherwise ought to set the value of the Var. An
example of this is interfacing with HTML input field change events.
The snd part of the result is an unsubscribe function.
mapVar :: (a -> b) -> Var a -> Fay (Var b) Source
Creates a Var that updates whenever the source var is changed, applying
the provided function to compute the new value.
mergeVars :: (a -> b -> c) -> Maybe (c -> (a, b)) -> Var a -> Var b -> Fay (Var c, Fay ()) Source
Creates a Var that updates whenever one of its source vars are changed.
If the 2nd argument is a Just value, then its used to set the source
vars when the variable is changed. Setting using a merged var is
sometimes preferred because both values are set before the subscribers
are called.
The snd part of the result is an unsubscribe function.
mergeVars' :: (a -> b -> c) -> Maybe (c -> (a, b)) -> Var a -> Var b -> Fay (Var c) Source
Like mergeVars, but discards the unsubscribe function.
tupleVars' :: Var a -> Var b -> Fay (Var (a, b)) Source
Like tupleVars, but discards the unsubscribe function.
waitForN :: Int -> Fay (Fay void -> Fay (), Sig ()) Source
Wait for n signals on the given signaller.
waitFor :: Var a -> (a -> Bool) -> (a -> Fay ()) -> Fay () Source
Wait for the given predicate to be satisfied on the var and then unsubscribe.
oneShot :: Subscribable (v a) => v a -> (a -> Fay ()) -> Fay () Source
Make a one-shot variable subscription that immediately unsubscribes after the event has triggered.