haste-compiler-0.2.99: Haskell To ECMAScript compiler

Safe HaskellNone

FRP.Fursuit

Description

Oversimplified FRP library, using no concurrency primitives. As it's primarily intended to be used with haste-compiler, compiled to Javascript, this library is NOT thread-safe, though it could be made so by simply slamming a global lock around the write and newSinkID operations.

Synopsis

Documentation

sink :: (a -> IO ()) -> Signal a -> IO ()Source

Attach a signal to an actuator.

new :: IO (Signal a) -> Signal aSource

Execute the specified IO action to obtain a new signal when registering signals. This is handy when you're creating a signal from an external event for use with a single sink: clicked <- buttonSig my_button sink (_ -> putStrLn Button clicked!) clicked -- ...can be rewritten as: sink (_ -> putStrLn Button clicked!) (new $ buttonSig my_button)

union :: Signal a -> Signal a -> Signal aSource

Create a signal that has the value of whichever parent signal fired last. The union is left biased.

accumS :: a -> Signal (a -> a) -> Signal aSource

Behaves pretty much like scanl on signals. Initialize the accumulator with a default value; every time the function signal triggers, apply the function to the accumulator and pass on the result.

filterS :: (a -> Bool) -> Signal a -> Signal aSource

Filter out events. filterS pred sig only lets the signal sig through if it fulfills the predicate pred. For example: (pa, a) <- pipe (0 :: Int) (pb, b) <- pipe (0 :: Int) let plus = (+) $ filterS (a <* b sink (putStrLn . show) plus write pa 20 write pb 20 write pa 5 The above code will print 20 and 25; writing 20 to pa gets filtered out, as 20 does not fulfull (< 10) so no signal is fired. b isn't so filtered however, so the 20 goes through just fine, and is added to the last good value of a (which is 0 - its initial value). The final 5 does fulfill (< 10), so the signal goes through and we get 25.

whenS :: Signal Bool -> Signal a -> Signal aSource

Only allow a signal to pass through when the time varying value is true.

zipS :: Signal a -> Signal b -> Signal (a, b)Source

Signal equivalent of the list function by the same name.

untilS :: (a -> Bool) -> Signal a -> Signal b -> Signal aSource

Pass through a signal as long as it does not fulfill a predicate. From the point when it does fulfill that predicate, the signal never propagates again unless the reset signal fired.

fromS :: (a -> Bool) -> Signal a -> Signal b -> Signal aSource

Don't pass the signal through until it fulfills a predicate. After the predicate has been fulfilled at least once, always propagate the signal.

stateful :: (st, a) -> Signal (st -> (st, a)) -> Signal aSource

Create a signal that keeps local state but returns another value.

unions :: [Signal a] -> Signal aSource

The union of n > 1 signals.

filterMapS :: (a -> Maybe b) -> Signal a -> Signal bSource

Combined fmap and filter.