Skip to content

Commit 857e67e

Browse files
authored
Merge pull request #11189 from cabalism/hlint/first-second
HLint: use first and use second
2 parents c5cefa2 + 6951598 commit 857e67e

File tree

9 files changed

+21
-19
lines changed

9 files changed

+21
-19
lines changed

.hlint.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@
2828
- ignore: {name: "Use ++"} # 4 hints
2929
- ignore: {name: "Use :"} # 28 hints
3030
- ignore: {name: "Use <$"} # 2 hints
31-
- ignore: {name: "Use <$>"} # 88 hints
31+
- ignore: {name: "Use <$>"} # 89 hints
3232
- ignore: {name: "Use <&>"} # 16 hints
3333
- ignore: {name: "Use <=<"} # 4 hints
3434
- ignore: {name: "Use =<<"} # 7 hints
35-
- ignore: {name: "Use =="} # 3 hints
35+
- ignore: {name: "Use =="} # 2 hints
3636
- ignore: {name: "Use >=>"} # 3 hints
3737
- ignore: {name: "Use Down"} # 3 hints
3838
- ignore: {name: "Use bimap"} # 7 hints
3939
- ignore: {name: "Use camelCase"} # 96 hints
4040
- ignore: {name: "Use catMaybes"} # 4 hints
4141
- ignore: {name: "Use concatMap"} # 2 hints
4242
- ignore: {name: "Use const"} # 37 hints
43-
- ignore: {name: "Use first"} # 5 hints
44-
- ignore: {name: "Use fmap"} # 24 hints
43+
- ignore: {name: "Use fmap"} # 23 hints
4544
- ignore: {name: "Use fold"} # 1 hint
4645
- ignore: {name: "Use fromMaybe"} # 5 hints
4746
- ignore: {name: "Use fst"} # 2 hints
@@ -57,7 +56,6 @@
5756
- ignore: {name: "Use record patterns"} # 16 hints
5857
- ignore: {name: "Use replicateM_"} # 2 hints
5958
- ignore: {name: "Use rights"} # 2 hints
60-
- ignore: {name: "Use second"} # 7 hints
6159
- ignore: {name: "Use section"} # 18 hints
6260
- ignore: {name: "Use tuple-section"} # 28 hints
6361
- ignore: {name: "Use typeRep"} # 2 hints

Cabal-syntax/src/Distribution/Compat/Graph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ instance Show a => Show (Graph a) where
128128
show = show . toList
129129

130130
instance (IsNode a, Read a, Show (Key a)) => Read (Graph a) where
131-
readsPrec d s = map (\(a, r) -> (fromDistinctList a, r)) (readsPrec d s)
131+
readsPrec d s = map (first fromDistinctList) (readsPrec d s)
132132

133133
instance (IsNode a, Binary a, Show (Key a)) => Binary (Graph a) where
134134
put x = put (toList x)

Cabal/src/Distribution/Simple/BuildTarget.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module Distribution.Simple.BuildTarget
4040
, reportBuildTargetProblems
4141
) where
4242

43+
import Data.Bifunctor (second)
4344
import Distribution.Compat.Prelude
4445
import Prelude ()
4546

@@ -407,7 +408,7 @@ reportBuildTargetProblems verbosity problems = do
407408
targets ->
408409
dieWithException verbosity $
409410
UnknownBuildTarget $
410-
map (\(target, nosuch) -> (showUserBuildTarget target, nosuch)) targets
411+
map (first showUserBuildTarget) targets
411412

412413
case [(t, ts) | BuildTargetAmbiguous t ts <- problems] of
413414
[] -> return ()
@@ -652,7 +653,7 @@ matchComponentKindAndName cs ckind str =
652653
orNoSuchThing (showComponentKind ckind ++ " component") str $
653654
increaseConfidenceFor $
654655
matchInexactly
655-
(\(ck, cn) -> (ck, caseFold cn))
656+
(second caseFold)
656657
[((cinfoKind c, cinfoStrName c), c) | c <- cs]
657658
(ckind, str)
658659

Cabal/src/Distribution/Utils/MapAccum.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module Distribution.Utils.MapAccum (mapAccumM) where
22

3+
import Data.Bifunctor (second)
34
import Distribution.Compat.Prelude
45
import Prelude ()
56

67
-- Like StateT but with return tuple swapped
78
newtype StateM s m a = StateM {runStateM :: s -> m (s, a)}
89

910
instance Functor m => Functor (StateM s m) where
10-
fmap f (StateM x) = StateM $ \s -> fmap (\(s', a) -> (s', f a)) (x s)
11+
fmap f (StateM x) = StateM $ \s -> fmap (second f) (x s)
1112

1213
instance Monad m => Applicative (StateM s m) where
1314
pure x = StateM $ \s -> return (s, x)

cabal-install/src/Distribution/Client/IndexUtils/ActiveRepos.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Distribution.Client.IndexUtils.ActiveRepos
1111
, organizeByRepos
1212
) where
1313

14+
import Data.Bifunctor (second)
1415
import Distribution.Client.Compat.Prelude
1516
import Distribution.Client.Types.RepoName (RepoName (..))
1617
import Prelude ()
@@ -177,12 +178,10 @@ organizeByRepos (ActiveRepos xs0) sel ys0 =
177178
go :: [a] -> [ActiveRepoEntry] -> [a] -> Either String ([a], [(a, CombineStrategy)])
178179
go _rest [] ys = Right (ys, [])
179180
go rest (ActiveRepoRest s : xs) ys =
180-
go rest xs ys <&> \(rest', result) ->
181-
(rest', map (\x -> (x, s)) rest ++ result)
181+
go rest xs ys <&> second (map (\x -> (x, s)) rest ++)
182182
go rest (ActiveRepo r s : xs) ys = do
183183
(z, zs) <- extract r ys
184-
go rest xs zs <&> \(rest', result) ->
185-
(rest', (z, s) : result)
184+
go rest xs zs <&> second ((z, s) :)
186185

187186
extract :: RepoName -> [a] -> Either String (a, [a])
188187
extract r = loop id

cabal-install/src/Distribution/Client/ProjectConfig.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module Distribution.Client.ProjectConfig
7676
, maxNumFetchJobs
7777
) where
7878

79+
import Data.Bifunctor (second)
7980
import Distribution.Client.Compat.Prelude hiding (empty)
8081
import Distribution.Parsec.Source
8182
import Distribution.Simple.Utils
@@ -1681,7 +1682,7 @@ syncAndReadSourcePackagesRemoteRepos
16811682
repoPaths
16821683

16831684
mapGroup :: Ord k => [(k, v)] -> [(k, NonEmpty v)]
1684-
mapGroup = Map.toList . Map.fromListWith (<>) . map (\(k, v) -> (k, pure v))
1685+
mapGroup = Map.toList . Map.fromListWith (<>) . map (second pure)
16851686

16861687
-- The repos in a group are given distinct names by simple enumeration
16871688
-- foo, foo-2, foo-3 etc

cabal-install/src/Distribution/Client/ProjectOrchestration.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ availableTargetIndexes installPlan = AvailableTargetIndexes{..}
853853
availableTargetsByPackageNameAndComponentName =
854854
Map.mapKeysWith
855855
(++)
856-
(\(pkgid, cname) -> (packageName pkgid, cname))
856+
(first packageName)
857857
availableTargetsByPackageIdAndComponentName
858858

859859
availableTargetsByPackageNameAndUnqualComponentName
@@ -952,7 +952,7 @@ availableTargetIndexesFromSourcePackages pkgSpecifiers = AvailableTargetIndexes{
952952
availableTargetsByPackageNameAndComponentName =
953953
Map.mapKeysWith
954954
(++)
955-
(\(pkgid, cname) -> (packageName pkgid, cname))
955+
(first packageName)
956956
availableTargetsByPackageIdAndComponentName
957957

958958
availableTargetsByPackageNameAndUnqualComponentName

cabal-install/src/Distribution/Client/TargetSelector.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import Control.Arrow ((&&&))
100100
import Control.Monad hiding
101101
( mfilter
102102
)
103+
import Data.Bifunctor (second)
103104
#if MIN_VERSION_base(4,20,0)
104105
import Data.Functor as UZ (unzip)
105106
#else
@@ -827,7 +828,7 @@ reportTargetSelectorProblems verbosity problems = do
827828
targets ->
828829
dieWithException verbosity $
829830
NoSuchTargetSelectorErr $
830-
map (\(target, nosuch) -> (showTargetString target, nosuch)) targets
831+
map (first showTargetString) targets
831832

832833
case [(t, ts) | TargetSelectorAmbiguous t ts <- problems] of
833834
[] -> return ()
@@ -2186,7 +2187,7 @@ matchComponentKindAndName cs ckind str =
21862187
(map render cs)
21872188
$ increaseConfidenceFor
21882189
$ matchInexactly
2189-
(\(ck, cn) -> (ck, caseFold cn))
2190+
(second caseFold)
21902191
(\c -> (cinfoKind c, cinfoStrName c))
21912192
cs
21922193
(ckind, str)

cabal-install/tests/UnitTests/Distribution/Solver/Modular/Builder.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module UnitTests.Distribution.Solver.Modular.Builder
44

55
import Distribution.Solver.Modular.Builder
66

7+
import Data.Bifunctor (second)
78
import Test.Tasty
89
import Test.Tasty.QuickCheck
910

@@ -15,7 +16,7 @@ tests =
1516
-- | Simpler splits implementation
1617
splits' :: [a] -> [(a, [a])]
1718
splits' [] = []
18-
splits' (x : xs) = (x, xs) : map (\(y, ys) -> (y, x : ys)) (splits' xs)
19+
splits' (x : xs) = (x, xs) : map (second (x :)) (splits' xs)
1920

2021
splitsTest :: [Int] -> Property
2122
splitsTest xs = splits' xs === splits xs

0 commit comments

Comments
 (0)