Replace some foldr with foldl'
This commit is contained in:
@@ -3,6 +3,7 @@ module Dodge.Creature.State (
|
||||
doDamage,
|
||||
) where
|
||||
|
||||
import Data.Foldable
|
||||
import Dodge.Base
|
||||
import Dodge.Corpse.Make
|
||||
import Dodge.Creature.Action
|
||||
@@ -34,9 +35,9 @@ foldCr ::
|
||||
World ->
|
||||
World
|
||||
--foldCr xs cr w = foldr ($ cr) w xs
|
||||
foldCr xs cr w = foldr f w xs
|
||||
foldCr xs cr w = foldl' f w $ reverse xs
|
||||
where
|
||||
f g w' = case w' ^? cWorld . creatures . ix (_crID cr) of
|
||||
f w' g = case w' ^? cWorld . creatures . ix (_crID cr) of
|
||||
Just cr' -> g cr' w'
|
||||
Nothing -> w'
|
||||
|
||||
@@ -216,13 +217,13 @@ upInv cr = cWorld . creatures . ix (_crID cr) . crInv %~ IM.mapWithKey (itemUpda
|
||||
|
||||
-- a loop going over equipped items
|
||||
equipmentEffects :: Creature -> World -> World
|
||||
equipmentEffects cr = flip (foldr $ useEquipment cr) (IM.keys $ _crInvEquipped cr)
|
||||
equipmentEffects cr = flip (foldl' $ flip $ useEquipment cr) (IM.keys $ _crInvEquipped cr)
|
||||
|
||||
-- a loop going over all inventory items
|
||||
invSideEff :: Creature -> World -> World
|
||||
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
|
||||
invSideEff cr w = weaponReloadSounds cr $ IM.foldlWithKey' f w (_crInv cr)
|
||||
where
|
||||
f i it w' =
|
||||
f w' i it =
|
||||
itemInvSideEffect cr it $
|
||||
doItemTargeting i cr w' & maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user