on ecc299a help sign in
reflex-vty/src/Reflex/Class/Switchable.hs
30 lines 962 B history raw
1{-|
2Module: Reflex.Class.Switchable
3Description: A class for things that can be switched on the firing of an event
4-}
5{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE FunctionalDependencies #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE UndecidableInstances #-}
9module Reflex.Class.Switchable where
11import Control.Monad
12import Reflex
14-- | Class representing things that can be switched when the provided event occurs
15class Reflex t => Switchable t w | w -> t where
16 switching :: MonadHold t m => w -> Event t w -> m w
18instance Reflex t => Switchable t (Event t a) where
19 switching = switchHold
21instance Reflex t => Switchable t (Dynamic t a) where
22 switching a e = fmap join $ holdDyn a e
24instance Reflex t => Switchable t (Behavior t a) where
25 switching = switcher
27instance (Reflex t, Switchable t a, Switchable t b) => Switchable t (a, b) where
28 switching (a, b) e = (,)
29 <$> (switching a $ fmap fst e)
30 <*> (switching b $ fmap snd e)