aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-11-30 04:02:11 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-11-30 04:02:17 +0100
commit80d1737c7ca12d3338428553968b37e3f5c2de4a (patch)
treeffaf44cb2577417261d5c2a9f58e3d8e4ef9e44f /app
parent650d139254a0e17be0b1011f2fda6ea67f903e71 (diff)
chore: define `(._N)` accessors for tuples
Diffstat (limited to 'app')
-rw-r--r--app/History.hs3
-rw-r--r--app/Main.hs14
-rw-r--r--app/Tuple.hs20
3 files changed, 28 insertions, 9 deletions
diff --git a/app/History.hs b/app/History.hs
index 9501b1b..6247108 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -8,6 +8,7 @@ import History.CommitInfo (CommitInfo (..), fromPartialCommitInfos, issueEvents)
import History.IssueEvent (IssueEvent (..))
import History.PartialCommitInfo (getPartialCommitInfos)
import Issue (Issue)
+import Tuple ()
import Prelude hiding (id, lines)
-- TODO Reduce cached data size
@@ -30,6 +31,6 @@ getHistory :: IO [(CommitHash, [IssueEvent], [Issue])]
getHistory = do
commitInfos <- fromPartialCommitInfos <$> getPartialCommitInfos
let commitHashes = map (.hash) commitInfos
- issueEventses = map snd $ issueEvents commitInfos
+ issueEventses = map (._2) $ issueEvents commitInfos
issueses = map (.issues) commitInfos
pure (zip3 commitHashes issueEventses issueses)
diff --git a/app/Main.hs b/app/Main.hs
index 26e3401..70ebf5e 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -410,6 +410,7 @@ import System.IO.Temp (withSystemTempFile)
import System.Process.Typed qualified as P
import Text.Printf
import TreeGrepper.Match qualified as G
+import Tuple ()
import Prelude hiding (id)
data Options = Options
@@ -545,7 +546,7 @@ idArg =
O.strArgument
( O.metavar "ID"
<> O.completer
- (O.listIOCompleter $ catMaybes . map I.id . trd3 . last <$> getHistory)
+ (O.listIOCompleter $ catMaybes . map I.id . (._3) . last <$> getHistory)
)
editFlag :: O.Parser Bool
@@ -571,7 +572,7 @@ main = do
. applyFilters filters
. filter withinPath
. applyClosed closed
- . trd3
+ . (._3)
. last
<$> getHistory
let groupedIssues = I.groupIssuesBy group ungroupedIssues
@@ -618,7 +619,7 @@ main = do
. applyFilters filters
. filter withinPath
. applyClosed closed
- . trd3
+ . (._3)
. last
<$> getHistory
putDoc colorize noPager width . P.vsep $
@@ -659,7 +660,7 @@ main = do
)
(reverse ess')
Options {colorize, width, command = Show {id, edit}} -> do
- issues <- trd3 . last <$> getHistory
+ issues <- (._3) . last <$> getHistory
issue <-
case find ((==) (Just id) . I.id) issues of
Nothing -> die (printf "no issue with id `%s'\n" id)
@@ -730,7 +731,7 @@ main = do
)
meta.referencedBy
Options {colorize, noPager, width, internalTags, command = Tags} -> do
- issues <- trd3 . last <$> getHistory
+ issues <- (._3) . last <$> getHistory
let tags =
concatMap
( \issue ->
@@ -819,6 +820,3 @@ putDoc colorize noPager width doc = do
else LT.putStr s
foreign import ccall "unistd.h isatty" c_isatty :: Int -> IO Int
-
-trd3 :: (a, b, c) -> c
-trd3 (_, _, c) = c
diff --git a/app/Tuple.hs b/app/Tuple.hs
new file mode 100644
index 0000000..8b43279
--- /dev/null
+++ b/app/Tuple.hs
@@ -0,0 +1,20 @@
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Tuple where
+
+import GHC.Records (HasField (..))
+
+instance HasField "_1" (a, b) a where
+ getField (a, _) = a
+
+instance HasField "_2" (a, b) b where
+ getField (_, b) = b
+
+instance HasField "_1" (a, b, c) a where
+ getField (a, _, _) = a
+
+instance HasField "_2" (a, b, c) b where
+ getField (_, b, _) = b
+
+instance HasField "_3" (a, b, c) c where
+ getField (_, _, c) = c