Add concept of GameRoom, check viewing distance based on rooms
This commit is contained in:
+35
-1
@@ -2,14 +2,18 @@
|
||||
module FoldableHelp
|
||||
( safeMinimumOn
|
||||
, safeMinimumOnMaybe
|
||||
, safeMinimumOnMaybeF
|
||||
, safeMinimumOnMaybeL
|
||||
, safeMinMaybeL
|
||||
, module Data.Foldable
|
||||
)
|
||||
where
|
||||
import Data.Foldable
|
||||
|
||||
import qualified Control.Foldl as L
|
||||
-- TODO check up whether and how it is necessary to specialise this
|
||||
-- | A version of 'minimum' where the comparison is done on some extracted value.
|
||||
-- Returns Nothing if the list is empty. Only calls the function once per element (not true).
|
||||
-- Returns Nothing if the list is empty.
|
||||
--
|
||||
-- > safeMinimumOn id [] == Nothing
|
||||
-- > safeMinimumOn length ["test","extra","a"] == Just "a"
|
||||
@@ -21,6 +25,34 @@ safeMinimumOn f = foldl' g Nothing
|
||||
| f x < f y = Just x
|
||||
| otherwise = Just y
|
||||
g Nothing y = Just y
|
||||
safeMinimumOnMaybeF :: (Ord b) => (a -> Maybe b) -> [a] -> Maybe a
|
||||
safeMinimumOnMaybeF f = L.fold $ L.Fold step initial extract
|
||||
where
|
||||
initial = Nothing
|
||||
step Nothing x = (x ,) <$> f x
|
||||
step (Just (a,x)) b = case f b of
|
||||
Just y | y < x -> Just (b,y)
|
||||
_ -> Just (a,x)
|
||||
extract = fmap fst
|
||||
safeMinMaybeL :: (Ord b) => (a -> Maybe b) -> L.Fold a (Maybe b)
|
||||
safeMinMaybeL f = L.Fold step initial id
|
||||
where
|
||||
initial = Nothing
|
||||
step Nothing x = f x
|
||||
step (Just x) b = case f b of
|
||||
Just y | y < x -> Just y
|
||||
_ -> Just x
|
||||
|
||||
safeMinimumOnMaybeL :: (Ord b) => (a -> Maybe b) -> L.Fold a (Maybe a)
|
||||
safeMinimumOnMaybeL f = L.Fold step initial extract
|
||||
where
|
||||
initial = Nothing
|
||||
step Nothing x = (x ,) <$> f x
|
||||
step (Just (a,x)) b = case f b of
|
||||
Just y | y < x -> Just (b,y)
|
||||
_ -> Just (a,x)
|
||||
extract = fmap fst
|
||||
|
||||
safeMinimumOnMaybe :: (Ord b) => (a -> Maybe b) -> [a] -> Maybe a
|
||||
safeMinimumOnMaybe f ys = fst <$> go Nothing ys
|
||||
where
|
||||
@@ -29,6 +61,8 @@ safeMinimumOnMaybe f ys = fst <$> go Nothing ys
|
||||
Just v | v < cmin -> go (Just (x,v)) xs
|
||||
_ -> go (Just (y,cmin)) xs
|
||||
go m _ = m
|
||||
|
||||
|
||||
--{- | Partial. -}
|
||||
--minimumOn :: Ord b => (a -> b) -> [a] -> a
|
||||
--minimumOn f [] = error "tried to take minimumOn of empty list"
|
||||
|
||||
Reference in New Issue
Block a user