Eta reduction
This commit is contained in:
+20
-14
@@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
module Dodge.Item.Grammar (
|
||||
invLDT,
|
||||
invLDT',
|
||||
@@ -152,8 +153,8 @@ itemToFunction itm = case itm ^. itType of
|
||||
CLICKER{} -> GadgetPlatformSF
|
||||
_ -> NoSF
|
||||
|
||||
structureToPotentialFunction :: LDTree ItemLink CItem -> S.Set ItemStructuralFunction
|
||||
structureToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of
|
||||
treeToPotentialFunction :: LDTree ItemLink CItem -> S.Set ItemStructuralFunction
|
||||
treeToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of
|
||||
STICKYMOD -> S.singleton GrenadeHitEffectSF
|
||||
ATTACH GIMBAL -> S.singleton ProjectileStabiliserSF
|
||||
ATTACH GYROSCOPE -> S.singleton ProjectileStabiliserSF
|
||||
@@ -169,18 +170,16 @@ type LDTComb a b = LDTree b a -> LDTree b a -> Maybe (LDTree b a)
|
||||
leftIsParentCombine :: LDTComb CItem ItemLink
|
||||
leftIsParentCombine ltree rtree = do
|
||||
let l = rightChildList ltree
|
||||
xs = dropWhile ((\s -> not $ S.member s (structureToPotentialFunction rtree)) . fst) l
|
||||
xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction rtree)) . fst) l
|
||||
(sf,linktype) <- safeHead xs
|
||||
return $
|
||||
ltree & ldtRight .:~ (linktype, rtree & ldtValue . _2 .~ sf)
|
||||
return $ ltree & ldtRight .:~ (linktype, rtree & ldtValue . _2 .~ sf)
|
||||
|
||||
rightIsParentCombine :: LDTComb CItem ItemLink
|
||||
rightIsParentCombine ltree rtree = do
|
||||
let l = leftChildList rtree
|
||||
xs = dropWhile ((\s -> not $ S.member s (structureToPotentialFunction ltree)) . fst) l
|
||||
xs = dropWhile ((\s -> not $ S.member s (treeToPotentialFunction ltree)) . fst) l
|
||||
(sf,linktype) <- safeHead xs
|
||||
return $
|
||||
rtree & ldtLeft .:~ (linktype, ltree & ldtValue . _2 .~ sf)
|
||||
return $ rtree & ldtLeft .:~ (linktype, ltree & ldtValue . _2 .~ sf)
|
||||
|
||||
leftChildList :: LDTree ItemLink CItem -> [(ItemStructuralFunction, ItemLink)]
|
||||
leftChildList t = foldl' f l (reverse $ t ^.. ldtLeft . each . _1)
|
||||
@@ -209,13 +208,20 @@ leftRightCombine f f' t1 t2 = f t1 t2 <|> checkdepth t1 t2
|
||||
checktop t t' = f' t t'
|
||||
|
||||
joinItemsInList :: (a -> a -> Maybe a) -> [a] -> [a]
|
||||
joinItemsInList f xs = snd $ h (xs, [])
|
||||
joinItemsInList f = fst . h . ([],)
|
||||
where
|
||||
h ([], zs) = ([], zs)
|
||||
h (y : ys, []) = h (ys, [y])
|
||||
h (y : ys, z : zs) = case f y z of
|
||||
Nothing -> h (ys, y : z : zs)
|
||||
Just w -> h (w : ys, zs)
|
||||
h (zs, []) = (zs, [])
|
||||
h ([],y : ys) = h ([y],ys)
|
||||
h ( z : zs, y : ys) = case f y z of
|
||||
Nothing -> h ( y : z : zs,ys)
|
||||
Just w -> h ( zs,w : ys)
|
||||
--joinItemsInList f xs = snd $ h (xs, [])
|
||||
-- where
|
||||
-- h ([], zs) = ([], zs)
|
||||
-- h (y : ys, []) = h (ys, [y])
|
||||
-- h (y : ys, z : zs) = case f y z of
|
||||
-- Nothing -> h (ys, y : z : zs)
|
||||
-- Just w -> h (w : ys, zs)
|
||||
|
||||
-- this puts the first elements in the intmap at the end of the list
|
||||
invLDT :: IM.IntMap Item -> [LDTree ItemLink CItem]
|
||||
|
||||
Reference in New Issue
Block a user