Skip to content

Commit

Permalink
use applyJust/applyWhen more
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Sep 14, 2024
1 parent db135d8 commit 93fd1a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/swarm-engine/Swarm/Game/State/Initialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Swarm.Game.World.Gen (Seed)
import Swarm.Language.Capability (constCaps)
import Swarm.Language.Syntax (allConst, erase)
import Swarm.Language.Types
import Swarm.Util (binTuples, (?))
import Swarm.Util (applyJust, applyWhen, binTuples, (?))
import System.Clock qualified as Clock
import System.Random (mkStdGen)

Expand Down Expand Up @@ -137,20 +137,18 @@ pureScenarioToGameState scenario theSeed now toRun gsc =
-- of the scenario description).
& ix baseID
. machine
%~ case initialCodeToRun of
Nothing -> id
Just t -> const $ initMachine t
%~ applyJust (const . initMachine <$> initialCodeToRun)
-- If we are in creative mode, give base all the things
& ix baseID
. robotInventory
%~ case scenario ^. scenarioOperation . scenarioCreative of
False -> id
True -> union (fromElems (map (0,) things))
%~ applyWhen
(scenario ^. scenarioOperation . scenarioCreative)
(union (fromElems (map (0,) things)))
& ix baseID
. equippedDevices
%~ case scenario ^. scenarioOperation . scenarioCreative of
False -> id
True -> const (fromList devices)
%~ applyWhen
(scenario ^. scenarioOperation . scenarioCreative)
(const (fromList devices))

running = case robotList of
[] -> False
Expand Down
5 changes: 2 additions & 3 deletions src/swarm-web/Swarm/Web.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import Swarm.TUI.Model hiding (SwarmKeyDispatchers (..))
import Swarm.TUI.Model.Dialog.Goal
import Swarm.TUI.Model.Repl (REPLHistItem, replHistory, replSeq)
import Swarm.TUI.Model.UI
import Swarm.Util (applyJust)
import Swarm.Util.RingBuffer
import Swarm.Web.Worldview
import System.Timeout (timeout)
Expand Down Expand Up @@ -312,9 +313,7 @@ webMain ::
webMain baton port appStateRef chan = catch (Warp.runSettings settings app) handleErr
where
settings = Warp.setPort port $ onReady Warp.defaultSettings
onReady = case baton of
Just mv -> Warp.setBeforeMainLoop $ putMVar mv WebStarted
Nothing -> id
onReady = applyJust $ Warp.setBeforeMainLoop . flip putMVar WebStarted <$> baton

server :: Server ToplevelAPI
server =
Expand Down

0 comments on commit 93fd1a5

Please sign in to comment.