-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Reactive Extensions for Haskell -- -- An implementation of functional reactive programming based on -- Microsoft's Reactive Extensions for .NET: -- http://msdn.microsoft.com/en-us/library/hh242985(v=VS.103).aspx. -- -- RxHaskell offers a monadic API, making it easier to interleave side -- effects and imperative-style code. @package RxHaskell @version 0.1 module Signal.Event -- | Represents an event that a signal might send. -- -- Signals may send any number of NextEvents, followed by one -- ErrorEvent or CompletedEvent. data Event v -- | A value v in the monad. NextEvent :: v -> Event v -- | Sent when an error or exception occurs in the signal. Outside of the -- monad. ErrorEvent :: IOException -> Event v -- | Sent when the signal completes successfully. Outside of the monad. CompletedEvent :: Event v instance [safe] Show v => Show (Event v) instance [safe] Eq v => Eq (Event v) module Disposable -- | Allows disposal of a resource by running an action in the monad -- m. data Disposable EmptyDisposable :: Disposable -- | Creates a disposable which runs the given action upon disposal. newDisposable :: IO () -> IO Disposable -- | Disposes a disposable. dispose :: Disposable -> IO () -- | A synchronized set of disposables. data DisposableSet -- | Creates a set of disposables. newDisposableSet :: IO DisposableSet -- | Adds a disposable to a set. addDisposable :: DisposableSet -> Disposable -> IO () -- | Removes a disposable from a set. removeDisposable :: DisposableSet -> Disposable -> IO () -- | Converts a set of disposables into a disposable. The constructed -- disposable will dispose of all disposables in the set. toDisposable :: DisposableSet -> IO Disposable instance [safe] Eq Disposable module Scheduler.Internal -- | An IO computation that must be performed in a scheduler of type -- s. data SchedulerIO s a SchedulerIO :: IO a -> SchedulerIO s a -- | Extracts the underlying IO action from a SchedulerIO -- action. -- -- This can be unsafe because the type system does not have enough -- information to determine whether the calling code is running on an -- appropriate scheduler. unsafeRunSchedulerIO :: Scheduler s => SchedulerIO s a -> IO a -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s schedule :: Scheduler s => s -> SchedulerIO s () -> IO Disposable schedulerMain :: Scheduler s => s -> IO () -- | A scheduler which runs enqueued actions in a dedicated background -- thread. newtype BackgroundScheduler BackgroundScheduler :: (TQueue (ScheduledAction BackgroundScheduler)) -> BackgroundScheduler -- | Represents an action on a scheduler, along with a flag indicating -- whether it should be canceled. data ScheduledAction s -- | Creates a new scheduled action, and returns a disposable which can be -- used to cancel it. newScheduledAction :: Scheduler s => SchedulerIO s () -> IO (ScheduledAction s, Disposable) -- | Executes the given action, then re-enters schedulerMain. executeScheduledAction :: Scheduler s => s -> ScheduledAction s -> IO () instance [safe] Scheduler BackgroundScheduler instance [safe] Scheduler s => Applicative (SchedulerIO s) instance [safe] Scheduler s => MonadIO (SchedulerIO s) instance [safe] Scheduler s => Monad (SchedulerIO s) instance [safe] Functor (SchedulerIO s) module Scheduler -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s schedule :: Scheduler s => s -> SchedulerIO s () -> IO Disposable -- | An IO computation that must be performed in a scheduler of type -- s. data SchedulerIO s a -- | A scheduler which runs enqueued actions in a dedicated background -- thread. data BackgroundScheduler -- | Creates a new background scheduler. newScheduler :: IO BackgroundScheduler module Scheduler.Main -- | A scheduler which runs enqueued actions on the main thread. data MainScheduler -- | Returns a scheduler representing the main thread. -- -- Note that runMainScheduler must be called for enqueued actions -- to actually execute. getMainScheduler :: IO MainScheduler -- | Runs the main scheduler indefinitely using the current thread. The -- current thread will be bound if possible. runMainScheduler :: IO () instance Scheduler MainScheduler module Scheduler.Unsafe instance (Scheduler s, Show v) => Show (SchedulerIO s v) module Signal.Subscriber.Internal -- | Receives events from a signal with values of type v and -- running in a scheduler of type s. -- -- Note that s refers to the scheduler that events must be sent -- on. Events are always sent synchronously, regardless of s. data Subscriber s v Subscriber :: (Event v -> SchedulerIO s ()) -> DisposableSet -> TVar ThreadId -> TVar Word32 -> TVar Bool -> Subscriber s v onEvent :: Subscriber s v -> Event v -> SchedulerIO s () disposables :: Subscriber s v -> DisposableSet lockedThread :: Subscriber s v -> TVar ThreadId threadLockCounter :: Subscriber s v -> TVar Word32 disposed :: Subscriber s v -> TVar Bool -- | Adds a disposable representing a subscription to the subscriber. If -- the subscriber is later sent completed or error, the disposable will -- be disposed. addSubscriptionDisposable :: Subscriber s v -> Disposable -> IO () -- | Disposes the subscriber, preventing it from receiving any new events. disposeSubscriber :: Subscriber s v -> IO () module Signal.Subscriber -- | Receives events from a signal with values of type v and -- running in a scheduler of type s. -- -- Note that s refers to the scheduler that events must be sent -- on. Events are always sent synchronously, regardless of s. data Subscriber s v -- | Constructs a subscriber. subscriber :: Scheduler s => (Event v -> SchedulerIO s ()) -> IO (Subscriber s v) -- | Synchronously sends an event to a subscriber. send :: Scheduler s => Subscriber s v -> Event v -> SchedulerIO s () -- | Represents an event that a signal might send. -- -- Signals may send any number of NextEvents, followed by one -- ErrorEvent or CompletedEvent. data Event v -- | A value v in the monad. NextEvent :: v -> Event v -- | Sent when an error or exception occurs in the signal. Outside of the -- monad. ErrorEvent :: IOException -> Event v -- | Sent when the signal completes successfully. Outside of the monad. CompletedEvent :: Event v module Signal -- | A signal which will send values of type v on a scheduler of -- type s. data Signal s v -- | Constructs a signal which sends its values to new subscribers -- synchronously. signal :: Scheduler s => (Subscriber s v -> SchedulerIO s Disposable) -> Signal s v -- | Subscribes to a signal. subscribe :: Scheduler s => Signal s v -> Subscriber s v -> SchedulerIO s Disposable -- | Creates a subscriber and subscribes to the signal. (>>:) :: Scheduler s => Signal s v -> (Event v -> SchedulerIO s ()) -> SchedulerIO s Disposable -- | Returns a signal which never sends any events. never :: Scheduler s => Signal s v -- | Returns a signal which immediately completes. empty :: Scheduler s => Signal s v -- | Represents an event that a signal might send. -- -- Signals may send any number of NextEvents, followed by one -- ErrorEvent or CompletedEvent. data Event v -- | A value v in the monad. NextEvent :: v -> Event v -- | Sent when an error or exception occurs in the signal. Outside of the -- monad. ErrorEvent :: IOException -> Event v -- | Sent when the signal completes successfully. Outside of the monad. CompletedEvent :: Event v -- | Allows disposal of a resource by running an action in the monad -- m. data Disposable -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s -- | An IO computation that must be performed in a scheduler of type -- s. data SchedulerIO s a instance [safe] Scheduler s => MonadZip (Signal s) instance [safe] Scheduler s => MonadPlus (Signal s) instance [safe] Scheduler s => Monoid (Signal s v) instance [safe] Scheduler s => Applicative (Signal s) instance [safe] Scheduler s => Functor (Signal s) instance [safe] Scheduler s => Monad (Signal s) module Signal.Channel -- | A controllable signal, represented by a Subscriber and -- Signal pair. -- -- Values sent to the subscriber will automatically be broadcast to all -- of the signal's subscribers. In effect, the subscriber is the write -- end, while the signal is the read end. type Channel s v = (Subscriber s v, Signal s v) -- | Creates a simple channel which broadcasts all values sent to it. -- -- Sending an ErrorEvent or CompletedEvent will terminate -- the channel. newChannel :: Scheduler s => IO (Channel s v) -- | Determines how many events a replay channel will save. data ChannelCapacity -- | The channel will only save the specified number of events. LimitedCapacity :: Int -> ChannelCapacity -- | The channel will save an unlimited number of events. UnlimitedCapacity :: ChannelCapacity -- | Like newChannel, but new subscriptions to the returned signal -- will receive all values (up to the specified capacity) which have been -- sent thus far. -- -- Sending an ErrorEvent or CompletedEvent will terminate -- the channel. Any terminating event will be replayed to future -- subscribers, assuming sufficient capacity. newReplayChannel :: Scheduler s => ChannelCapacity -> IO (Channel s v) -- | A signal which will send values of type v on a scheduler of -- type s. data Signal s v -- | Receives events from a signal with values of type v and -- running in a scheduler of type s. -- -- Note that s refers to the scheduler that events must be sent -- on. Events are always sent synchronously, regardless of s. data Subscriber s v -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s instance [safe] Eq ChannelCapacity instance [safe] Show ChannelCapacity module Signal.Connection -- | Multicasts a signal to many subscribers, without triggering any side -- effects more than once. data Connection s v -- | Creates a connection that will subscribe to the given base signal, and -- forward all events onto the given channel. multicast :: Scheduler s => Signal s v -> Channel s v -> IO (Connection s v) -- | Multicasts to a simple channel. publish :: Scheduler s => Signal s v -> IO (Connection s v) -- | Activates a connection by subscribing to its underlying signal. -- Calling this function multiple times just returns the existing -- disposable. connect :: Scheduler s => Connection s v -> SchedulerIO s Disposable -- | Returns the multicasted signal of a connection. -- -- No events will be sent on the resulting signal until connect is -- invoked. multicastedSignal :: Connection s v -> Signal s v -- | Multicasts to a replay channel of unlimited capacity, then connects -- immediately. replay :: Scheduler s => Signal s v -> SchedulerIO s (Signal s v) -- | Multicasts to a replay channel of capacity 1, then connects -- immediately. replayLast :: Scheduler s => Signal s v -> SchedulerIO s (Signal s v) -- | A controllable signal, represented by a Subscriber and -- Signal pair. -- -- Values sent to the subscriber will automatically be broadcast to all -- of the signal's subscribers. In effect, the subscriber is the write -- end, while the signal is the read end. type Channel s v = (Subscriber s v, Signal s v) -- | A signal which will send values of type v on a scheduler of -- type s. data Signal s v -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s -- | An IO computation that must be performed in a scheduler of type -- s. data SchedulerIO s a -- | Allows disposal of a resource by running an action in the monad -- m. data Disposable module Signal.Operators -- | Runs a side-effecting action whenever the signal sends an event. doEvent :: Scheduler s => Signal s v -> (Event v -> SchedulerIO s ()) -> Signal s v -- | Runs a side-effecting action whenever the signal sends a value. doNext :: Scheduler s => Signal s v -> (v -> SchedulerIO s ()) -> Signal s v -- | Runs a side-effecting action whenever the signal sends an error. doError :: Scheduler s => Signal s v -> (IOException -> SchedulerIO s ()) -> Signal s v -- | Runs a side-effecting action when the signal completes. doCompleted :: Scheduler s => Signal s v -> SchedulerIO s () -> Signal s v -- | Runs a side-effecting action when the signal completes or errors. finally :: Scheduler s => Signal s v -> SchedulerIO s () -> Signal s v -- | Brings every signal event into the monad, as a NextEvent -- containing the event itself. materialize :: Scheduler s => Signal s v -> Signal s (Event v) -- | The inverse of materialize. dematerialize :: Scheduler s => Signal s (Event v) -> Signal s v -- | Turns any Foldable into a signal. fromFoldable :: (Foldable t, Scheduler s) => t v -> Signal s v -- | Returns a signal of mapped values. map :: Scheduler s => Signal s v -> (v -> w) -> Signal s w -- | Filters the values of a signal according to a predicate. filter :: Scheduler s => Signal s v -> (v -> Bool) -> Signal s v -- | Returns a signal of the first n elements. take :: (Integral n, Scheduler s) => Signal s v -> n -> Signal s v -- | Returns a signal without the first n elements. drop :: (Integral n, Scheduler s) => Signal s v -> n -> Signal s v -- | Returns a signal that sends the values from the most recently sent -- signal. switch :: Scheduler s => Signal s (Signal s v) -> Signal s v -- | Combines the latest values sent by both signals. combine :: Scheduler s => Signal s a -> Signal s b -> Signal s (a, b) -- | Returns a signal which never sends any events. never :: Scheduler s => Signal s v -- | Returns a signal which immediately completes. empty :: Scheduler s => Signal s v -- | A signal which will send values of type v on a scheduler of -- type s. data Signal s v module Signal.Scheduled -- | Starts a signal which executes action on s. start :: Scheduler s => s -> (Subscriber s v -> SchedulerIO s ()) -> IO (Signal s v) -- | Returns a signal which subscribes to sig on scheduler -- sch. subscribeOn :: (Scheduler s, Scheduler t) => Signal s v -> t -> Signal t v -- | Returns a signal which delivers the events of sig on -- scheduler sch. deliverOn :: (Scheduler s, Scheduler t) => Signal s v -> t -> Signal t v -- | Synchronously waits for the signal to send an event. first :: Scheduler s => Signal s v -> IO (Event v) -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s -- | An IO computation that must be performed in a scheduler of type -- s. data SchedulerIO s a -- | A signal which will send values of type v on a scheduler of -- type s. data Signal s v module Signal.Command -- | A signal triggered in response to some action, typically UI-related. data Command v -- | Determines a command's behavior. data CommandPolicy -- | The command can only be executed once at a time. Attempts to -- execute while the command is already running will fail. ExecuteSerially :: CommandPolicy -- | The command can be executed concurrently any number of times. ExecuteConcurrently :: CommandPolicy -- | Creates a command. newCommand :: CommandPolicy -> Signal MainScheduler Bool -> SchedulerIO MainScheduler (Command v) -- | Sends whether this command is able to execute. -- -- This signal will always send at least one value immediately upon -- subscription. canExecute :: Command v -> Signal MainScheduler Bool -- | Sends whether this command is currently executing. -- -- This signal will always send at least one value immediately upon -- subscription. executing :: Command v -> Signal MainScheduler Bool -- | Attempts to execute a command. execute :: Command v -> v -> SchedulerIO MainScheduler Bool -- | A signal of the values passed to execute. values :: Command v -> Signal MainScheduler v -- | Creates a signal whenever the command executes, then subscribes to it. onExecute :: Command v -> (v -> Signal BackgroundScheduler ()) -> SchedulerIO MainScheduler (Signal MainScheduler (Signal BackgroundScheduler ())) -- | A signal of errors received from all signals created by -- onExecute. errors :: Command v -> Signal MainScheduler IOException -- | A controllable signal, represented by a Subscriber and -- Signal pair. -- -- Values sent to the subscriber will automatically be broadcast to all -- of the signal's subscribers. In effect, the subscriber is the write -- end, while the signal is the read end. type Channel s v = (Subscriber s v, Signal s v) -- | A signal which will send values of type v on a scheduler of -- type s. data Signal s v -- | Represents a queue of IO actions which can be executed in FIFO -- order. class Scheduler s -- | An IO computation that must be performed in a scheduler of type -- s. data SchedulerIO s a -- | A scheduler which runs enqueued actions in a dedicated background -- thread. data BackgroundScheduler -- | A scheduler which runs enqueued actions on the main thread. data MainScheduler instance [safe] Eq CommandPolicy instance [safe] Show CommandPolicy