Replace some foldr with foldl'

This commit is contained in:
2022-08-23 15:40:15 +01:00
parent 12ce2365c2
commit 9f00e67298
11 changed files with 35 additions and 30 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ module Dodge.Creature.Impulse (
impulsiveAIBefore,
) where
import Data.Foldable
import Control.Monad.State
import Data.Bifunctor
import Dodge.Creature.Impulse.Movement
@@ -29,7 +30,7 @@ impulsiveAIBefore f cr w = g w & cWorld . creatures . ix (_crID cr) .~ cr'
(g, cr') = followImpulses w $ f w cr
followImpulses :: World -> Creature -> (World -> World, Creature)
followImpulses w cr = foldr f (id, cr) (_apImpulse $ _crActionPlan cr)
followImpulses w cr = foldl' (flip f) (id, cr) (reverse $ _apImpulse $ _crActionPlan cr)
where
f imp (theupdate, cr') = first (. theupdate) $ followImpulse cr' w imp