This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- WTF instant creates a Maybe Instant | |
| toLight :: StupidIntermediateStrMapThingy -> Maybe Lights | |
| toLight = | |
| foldlWithIndex (\k m v -> do | |
| let transitionStart = instant (Milliseconds v.transitionStart) | |
| let transitionTime = Milliseconds v.transitionTime | |
| insert (LightId k) (Light v { transitionStart = transitionStart, transitionTime = transitionTime }) m | |
| ) empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| newtype Light = Light | |
| { color :: LightColor | |
| , prevColor :: LightColor | |
| , transitionStart :: Instant | |
| , transitionTime :: Milliseconds | |
| } | |
| derive newtype instance rfLight :: ReadForeign Light | |
| -- No type class instance was found for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setLight | |
| :: forall e | |
| . LuminaireId | |
| -> LightId | |
| -> LightColor | |
| -> (Maybe Milliseconds) | |
| -> Luminaires | |
| -> Eff (ref :: REF, now :: NOW | e) Boolean | |
| setLight id lid color transitionTime luminaires = do | |
| light <- getLuminaireLight id lid luminaires |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nextState | |
| :: forall e | |
| . Light | |
| -> LightColor | |
| -> (Maybe Milliseconds) | |
| -> Eff (now :: NOW | e) Light | |
| nextState light nextColor transitionTime = do | |
| wrap { color: nextColor | |
| , prevColor: nextColor | |
| , transitionStart: now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getLuminaireLight | |
| :: forall e | |
| . LuminaireId | |
| -> LightId | |
| -> Luminaires | |
| -> Eff (ref :: REF | e) (Maybe Light) | |
| getLuminaireLight id lid luminaires = do | |
| luminaire <- getLuminaire id luminaires | |
| let lights = _.lights <<< unwrap <$> luminaire | |
| let light = lookup lid <$> lights |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- types | |
| newtype LightId = LightId String | |
| instance showLightId :: Show LightId where | |
| show (LightId id) = show id | |
| derive instance eqLightId :: Eq LightId | |
| derive instance ordLightId :: Ord LightId | |
| derive instance newtypeLightId :: Newtype LightId _ | |
| newtype Light = Light |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| newtype LuminaireState = LuminaireState | |
| { gateway :: GatewayId | |
| , lights :: Map LightId LightState | |
| } | |
| derive instance newtypeLuminaireState :: Newtype LuminaireState _ | |
| ... | |
| setLight :: forall e. LuminaireId -> LightId -> LightColor -> Maybe Milliseconds -> AppState -> Eff (ref :: REF | e) Boolean | |
| setLight luminaireId lightId color transitionTime appState = do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setLight :: forall e. LuminaireId -> LightId -> LightState -> AppState -> Eff (ref :: REF | e) Boolean | |
| setLight luminaireId lightId lightState appState = do | |
| curLuminaireStateMaybe <- lookup luminaireId (liftEff $ readRef appState) | |
| case curLuminaireStateMaybe of | |
| Just curLuminaireState -> | |
| modifyRef appState (\luminaires -> insert luminaireId ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Could not match type | |
| Maybe | |
| with type | |
| Map LuminaireId | |
| while trying to match type Maybe t1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Counter where | |
| import Prelude hiding (apply) | |
| import Control.Monad.Eff (Eff) | |
| import Control.Monad.Eff.Class (liftEff) | |
| import Control.Monad.Eff.Console (CONSOLE, log) | |
| import Control.Monad.Eff.Ref (REF, Ref, modifyRef, newRef, readRef) | |
| import Data.Int (fromString) | |
| import Data.Maybe (fromMaybe) |