summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Firth <locallycompact@gmail.com>2018-07-04 12:05:54 +0100
committerDaniel Firth <locallycompact@gmail.com>2018-07-04 12:11:06 +0100
commitf32eec3e60051f9ce8b53f8045b78ac63ccde6d7 (patch)
tree8a9f1939774a9e2904eb5ff5c10901b26c940178
parent2df07b168393a398d04d80a3d248e582e0171d67 (diff)
Use NonEmpty instance in base
-rw-r--r--Bustle/Diagram.hs8
-rw-r--r--Bustle/Renderer.hs2
-rw-r--r--Bustle/Util.hs16
3 files changed, 5 insertions, 21 deletions
diff --git a/Bustle/Diagram.hs b/Bustle/Diagram.hs
index 0f35658..8bbe984 100644
--- a/Bustle/Diagram.hs
+++ b/Bustle/Diagram.hs
@@ -48,6 +48,7 @@ module Bustle.Diagram
where
import Data.List (unzip4)
+import Data.List.NonEmpty (NonEmpty(..), toList)
import Control.Arrow ((&&&))
import Control.Monad.Reader
@@ -59,7 +60,6 @@ import Graphics.Rendering.Pango.Font
import qualified Bustle.Marquee as Marquee
import Bustle.Marquee (Marquee)
-import Bustle.Util
import Bustle.Types (ObjectPath, InterfaceName, MemberName)
-- Sorry Mum
@@ -160,7 +160,7 @@ mapX f s = case s of
Arc {} -> s { topx = f (topx s)
, bottomx = f (bottomx s)
}
- ClientLines {} -> s { shapexs = mapNonEmpty f (shapexs s) }
+ ClientLines {} -> s { shapexs = f <$> shapexs s }
_ -> s { shapex = f (shapex s) }
mapY f s = case s of
@@ -219,7 +219,7 @@ headerHeight = fromIntegral . (10 *) . length
bounds :: Shape -> Rect
bounds s = case s of
ClientLines {} ->
- let xs = nonEmptyToList (shapexs s)
+ let xs = toList (shapexs s)
in (minimum xs, shapey1 s, maximum xs, shapey2 s)
Rule {} -> (shapex1 s, shapey s, shapex2 s, shapey s)
Arrow {} ->
@@ -503,7 +503,7 @@ drawTimestamp ts x y = do
drawClientLines :: NonEmpty Double -> Double -> Double -> Render ()
drawClientLines xs y1 y2 = saved $ do
setSourceRGB 0.7 0.7 0.7
- forM_ (nonEmptyToList xs) $ \x -> do
+ forM_ (toList xs) $ \x -> do
moveTo x y1
lineTo x y2
stroke
diff --git a/Bustle/Renderer.hs b/Bustle/Renderer.hs
index 2771c17..2f4c685 100644
--- a/Bustle/Renderer.hs
+++ b/Bustle/Renderer.hs
@@ -38,8 +38,8 @@ where
import Bustle.Types
import Bustle.Diagram
import Bustle.Regions
-import Bustle.Util (NonEmpty(..))
+import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.Set as Set
import Data.Set (Set)
import qualified Data.Map as Map
diff --git a/Bustle/Util.hs b/Bustle/Util.hs
index f0d1990..425f2aa 100644
--- a/Bustle/Util.hs
+++ b/Bustle/Util.hs
@@ -26,10 +26,6 @@ module Bustle.Util
-- You probably don't actually want to use this function.
, traceM
-
- , NonEmpty(..)
- , mapNonEmpty
- , nonEmptyToList
)
where
@@ -63,15 +59,3 @@ getCacheDir = do
let dir = dotCache </> "bustle"
createDirectoryIfMissing True dir
return dir
-
--- I don't want to depend on 'semigroups' for this.
-data NonEmpty a = a :| [a]
- deriving (Show, Eq)
-
-mapNonEmpty :: (a -> b)
- -> NonEmpty a
- -> NonEmpty b
-mapNonEmpty f (x :| xs) = f x :| map f xs
-
-nonEmptyToList :: NonEmpty a -> [a]
-nonEmptyToList (x :| xs) = x:xs