-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Hot-swappable FRP
--   
--   FRP for livecoding. You can hot-swap pieces or the whole of an FRP
--   graph while it's running.
--   
--   Small examples are in <a>Midair.Examples</a>
--   
--   The API may change a lot in the future.
@package midair
@version 0.2.0.1

module Midair.Core

-- | Signal flow
--   
--   A little like a function: takes a value of type <tt>a</tt> and returns
--   one of type <tt>c</tt>
data SFlow a c

-- | Apply a function to the input signal
sMap :: (a -> c) -> SFlow a c

-- | Accumulate a value. "Folding over the past".
sFold :: c -> (a -> c -> c) -> SFlow a c

-- | Like <a>sFold</a> but with no default. Useful for functions like
--   <tt>min</tt> which don't have a semantics of a result from one
--   argument
sFoldNoDefault :: (a -> Maybe c -> c) -> SFlow a c

-- | This name may change
sFoldAccum :: Maybe c -> (a -> Maybe c -> c) -> SFlow a c

-- | Compose two signal flows into one. The equivalent of '(.)'
sCompose :: SFlow b c -> SFlow a b -> SFlow a c

-- | Zip two signal flows together into one which returns a signal of
--   two-tuples
sZip :: SFlow a b -> SFlow a c -> SFlow a (b, c)

-- | Filter out the incoming signal by a predicate. Also check out
--   <a>sFilterWDefault</a>
sFilter :: (b -> Bool) -> SFlow b (Maybe b)

-- | Pass in a signal flow graph and get back a reference you can use to
--   hot-swap with
mkNodeRef :: SFlow i o -> IO (SFNodeRef i o)
data SFNodeRef a c

-- | Turn the result of <a>mkNodeRef</a> into something you can use in an
--   <a>SFlow</a> graph
nRef :: SFNodeRef a c -> SFlow a c

-- | Swap out part or whole of a signal flow graph with a new one of the
--   same type.
hotSwap :: SFNodeRef a c -> (Maybe c -> SFlow a c) -> IO ()
hotSwapSTM :: SFNodeRef a c -> (Maybe c -> SFlow a c) -> STM ()

-- | Given a node in the graph, and an input to that node, return the
--   output of that node and the "new node" with updated state
fireGraph :: TVar (SFlow a c) -> a -> STM c
fireGraphIO :: TVar (SFlow a c) -> a -> IO c
instance GHC.Base.Functor (Midair.Core.SFlow a)
instance GHC.Base.Applicative (Midair.Core.SFlow a)
instance Control.Category.Category Midair.Core.SFlow
instance Control.Arrow.Arrow Midair.Core.SFlow

module Midair.Handy

-- | Representation of side-effecting actions. Usually the final result of
--   the FRP graph
data Fx a
[Fx_Void] :: IO () -> Fx a
[Fx_Return] :: IO a -> Fx a
runFx :: Fx a -> IO (Maybe a)

-- | Handy for developing
sPrint :: Show a => SFlow a (Fx b)
sPutStrLn :: SFlow String (Fx b)

-- | Max of all values
sMax :: Ord x => SFlow x x

-- | Hotswap version of <a>sMax</a>
sMaxHS :: Ord x => Maybe x -> SFlow x x

-- | Min of all values
sMin :: Ord x => SFlow x x

-- | Hotswap version of <a>sMin</a>
sMinHS :: Ord x => Maybe x -> SFlow x x

-- | Add all values from the input stream
sSum :: Num n => SFlow n n

-- | Hotswap version of <a>sSum</a>
sSumHS :: Num n => Maybe n -> SFlow n n

-- | Multiply all values from the input stream
sProduct :: Num n => SFlow n n

-- | Hotswap version of <a>sProduct</a>
sProductHS :: Num n => Maybe n -> SFlow n n

-- | Return True if all input signal values have been True, otherwise False
sAnd :: SFlow Bool Bool

-- | Return True if any input signal values have been true
sOr :: SFlow Bool Bool

-- | Return True if any input signals have passed the predicate, False
--   otherwise
sAny :: (a -> Bool) -> SFlow a Bool

-- | Hotswap version of <a>sAny</a>
sAnyHS :: (a -> Bool) -> Maybe Bool -> SFlow a Bool

-- | Return True if all input signals have passed the predicate, False
--   otherwise
sAll :: (a -> Bool) -> SFlow a Bool

-- | Hotswap version of <a>sAll</a>
sAllHS :: (a -> Bool) -> Maybe Bool -> SFlow a Bool

-- | <a>mappend</a> all input signal values
--   
--   (If you care whether they're appended on the right or left, use
--   <a>sMappendL</a> or <a>sMappendR</a>)
sMappend :: Monoid x => SFlow x x

-- | Hotswap version of <a>sMappend</a>
sMappendHS :: Monoid x => Maybe x -> SFlow x x

-- | <a>mappend</a> new values onto the left
sMappendL :: Monoid x => SFlow x x

-- | Hotswap version of <a>sMappendL</a>
sMappendLHS :: Monoid x => Maybe x -> SFlow x x

-- | <a>mappend</a> new values onto the right
sMappendR :: Monoid x => SFlow x x

-- | Hotswap version of <a>sMappendR</a>
sMappendRHS :: Monoid x => Maybe x -> SFlow x x

-- | Returns list of all values - at the head of the list is the
--   most-recent element
sToList :: SFlow a [a]
sToListHS :: Maybe [a] -> SFlow a [a]

-- | Return True if the input signal has ever contained the element, else
--   False
sElem :: Eq x => x -> SFlow x Bool

-- | Return True if the input signal has never contained the element, else
--   False
sNotElem :: Eq x => x -> SFlow x Bool
sMapMaybe :: state -> (update -> Maybe state) -> SFlow update state
sFilterWDefault :: (b -> Bool) -> b -> SFlow b b

-- | Hot-swap in a fold function
--   
--   First argument is the default value, in case the graph you're
--   replacing hasn't fired at all yet
sFoldHS :: c -> (a -> c -> c) -> Maybe c -> SFlow a c

-- | Count the number of <a>Just</a> values we've seen
--   
--   (Useful after e.g. a <a>sFilter</a>)
sCountJust :: Num n => SFlow (Maybe a) n

-- | Hotswap version of <a>sCountJust</a>
sCountJustHS :: Num n => Maybe n -> SFlow (Maybe a) n

-- | <tt>countJust</tt> by steps -- e.g. <tt>[0,3,6]</tt> instead of
--   <tt>[0,1,2]</tt>
sCountJustBy :: Num n => n -> SFlow (Maybe a) n

-- | Hotswap version of <a>sCountJustBy</a>
sCountJustByHS :: Num n => n -> Maybe n -> SFlow (Maybe a) n

-- | Count of all values -- essentially the number of times the SFlow has
--   fired
--   
--   (If you want to count e.g. what's passed the predicate in
--   <a>sFilter</a>, use <a>sCountJust</a> instead)
sCountFires :: Num n => SFlow x n
sCountFiresBy :: Num n => n -> SFlow x n
sCountFiresByHS :: Num n => n -> Maybe n -> SFlow x n


-- | The simplest input: keypresses. Nice for testing.
module Midair.GetChar
runGetChar :: SFlow GetChar (Fx a) -> IO (ThreadId, ThreadId, SFNodeRef GetChar (Fx a))
data GetChar
GetChar :: Char -> GetChar
instance GHC.Classes.Ord Midair.GetChar.GetChar
instance GHC.Classes.Eq Midair.GetChar.GetChar
instance GHC.Read.Read Midair.GetChar.GetChar
instance GHC.Show.Show Midair.GetChar.GetChar


-- | Everything reexported so you can just "import Midair" when livecoding
module Midair

module Midair.Examples.MaxToMin
hotswapMaxToMin :: IO ()

module Midair.Examples.HotswapCount
hotswapCount :: IO ()

module Midair.Examples
