Skip to content

Instantly share code, notes, and snippets.

-- 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
newtype Light = Light
{ color :: LightColor
, prevColor :: LightColor
, transitionStart :: Instant
, transitionTime :: Milliseconds
}
derive newtype instance rfLight :: ReadForeign Light
-- No type class instance was found for
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
nextState
:: forall e
. Light
-> LightColor
-> (Maybe Milliseconds)
-> Eff (now :: NOW | e) Light
nextState light nextColor transitionTime = do
wrap { color: nextColor
, prevColor: nextColor
, transitionStart: now
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
-- 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
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
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 )
Could not match type
Maybe
with type
Map LuminaireId
while trying to match type Maybe t1
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)