File tree Expand file tree Collapse file tree 7 files changed +20
-33
lines changed Expand file tree Collapse file tree 7 files changed +20
-33
lines changed Original file line number Diff line number Diff line change 26862686 lhs : " Data.Bool.bool True"
26872687 rhs : " Use `whenTrue` from HNix Prelude"
26882688
2689+ - hint :
2690+ lhs : " maybe mempty"
2691+ note : " Use `whenJust`"
2692+ rhs : whenJust
Original file line number Diff line number Diff line change @@ -207,10 +207,7 @@ foldNixPath z f =
207207 go
208208 z
209209 $ (fromInclude . stringIgnoreContext <$> dirs)
210- <> maybe
211- mempty
212- uriAwareSplit
213- mPath
210+ <> uriAwareSplit `whenJust` mPath
214211 <> [ fromInclude $ " nix=" <> toText dataDir <> " /nix/corepkgs" ]
215212 where
216213
Original file line number Diff line number Diff line change @@ -132,15 +132,14 @@ prettyParams :: Params (NixDoc ann) -> Doc ann
132132prettyParams (Param n ) = prettyVarName n
133133prettyParams (ParamSet mname variadic pset) =
134134 prettyParamSet variadic pset <>
135- maybe
135+ toDoc `whenJust` mname
136+ where
137+ toDoc :: VarName -> Doc ann
138+ toDoc (coerce -> name) =
139+ bool
136140 mempty
137- (\ (coerce -> name) ->
138- bool
139- mempty
140- (" @" <> pretty name)
141- (not (Text. null name))
142- )
143- mname
141+ (" @" <> pretty name)
142+ (not (Text. null name))
144143
145144prettyParamSet :: Variadic -> ParamSet (NixDoc ann ) -> Doc ann
146145prettyParamSet variadic args =
@@ -164,10 +163,7 @@ prettyBind (Inherit s ns _p) =
164163 " inherit " <> scope <> align (fillSep $ prettyVarName <$> ns) <> " ;"
165164 where
166165 scope =
167- maybe
168- mempty
169- ((<> " " ) . parens . withoutParens)
170- s
166+ ((<> " " ) . parens . withoutParens) `whenJust` s
171167
172168prettyKeyName :: NKeyName (NixDoc ann ) -> Doc ann
173169prettyKeyName (StaticKey " " ) = " \"\" "
@@ -255,10 +251,7 @@ exprFNixDoc = \case
255251 where
256252 r = mkNixDoc selectOp (wrapParens appOpNonAssoc r')
257253 ordoc =
258- maybe
259- mempty
260- ((" or " <> ) . wrapParens appOpNonAssoc)
261- o
254+ ((" or " <> ) . wrapParens appOpNonAssoc) `whenJust` o
262255 NHasAttr r attr ->
263256 mkNixDoc hasAttrOp (wrapParens hasAttrOp r <> " ? " <> prettySelector attr)
264257 NEnvPath p -> simpleExpr $ pretty @ String $ coerce $ " <" <> p <> " >"
Original file line number Diff line number Diff line change @@ -55,10 +55,7 @@ renderFrames (x : xs) = do
5555 where
5656 go :: NixFrame -> [Doc ann ]
5757 go f =
58- maybe
59- mempty
60- (\ pos -> [" While evaluating at " <> pretty (sourcePosPretty pos) <> colon])
61- (framePos @ v @ m f)
58+ (\ pos -> [" While evaluating at " <> pretty (sourcePosPretty pos) <> colon]) `whenJust` framePos @ v @ m f
6259
6360framePos
6461 :: forall v (m :: Type -> Type )
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ freeVars e = case unFix e of
6868 Set. unions
6969 [ freeVars expr
7070 , pathFree path
71- , maybe mempty freeVars orExpr
71+ , freeVars `whenJust` orExpr
7272 ]
7373 (NHasAttr expr path) -> freeVars expr <> pathFree path
7474 (NAbs (Param varname) expr) -> Set. delete varname (freeVars expr)
@@ -79,7 +79,7 @@ freeVars e = case unFix e of
7979 Set. difference
8080 (Set. unions $ freeVars <$> mapMaybe snd pset)
8181 (Set. difference
82- (maybe mempty one varname)
82+ (one `whenJust` varname)
8383 (Set. fromList $ fst <$> pset)
8484 )
8585 (NLet bindings expr ) ->
Original file line number Diff line number Diff line change @@ -195,11 +195,10 @@ whenJust
195195 => (a -> b )
196196 -> Maybe a
197197 -> b
198- whenJust f ma =
198+ whenJust =
199199 maybe
200200 mempty
201- f
202- ma
201+ {-# inline whenJust #-}
203202
204203
205204-- | Apply a single function to both components of a pair.
Original file line number Diff line number Diff line change @@ -111,10 +111,7 @@ paramsXML (ParamSet mname variadic pset) =
111111 [ Attr (unqual " ellipsis" ) " 1" ]
112112 (variadic == Variadic )
113113 nattr =
114- maybe
115- mempty
116- ((: mempty ) . Attr (unqual " name" ) . toString)
117- mname
114+ ((: mempty ) . Attr (unqual " name" ) . toString) `whenJust` mname
118115
119116paramSetXML :: ParamSet r -> [Content ]
120117paramSetXML = fmap (\ (k, _) -> Elem $ mkEName " attr" (toString k))
You can’t perform that action at this time.
0 commit comments