Closed jvoigtlaender closed 10 months ago
Also, what do you think of the following three rules?
- warn: {lhs: catMaybes (concat x), rhs: concatMap catMaybes x}
- hint: {lhs: filter f (concat x), rhs: concatMap (filter f) x}
- warn: {lhs: mapMaybe f (concat x), rhs: concatMap (mapMaybe f) x}
All three should be efficiency improvements (since stuff is potentially filtered away before concatenating, so there is less work to do for ++
, due to shorter lists).
Also possible would be:
- hint: {lhs: "concat (fromMaybe [] x)", rhs: "maybe [] concat x"}
- warn: {lhs: fold (concat x), rhs: foldMap fold x}
- warn: {lhs: foldMap f (concat x), rhs: foldMap (foldMap f) x}
Sorry for the delay in getting to this. The renamings look good.
As for the other hints, the three moving to use concatMap look great. The one moving to maybe [] concat x
looks reasonable. I worry about the ones that merge concat with fold are a bit more complex? In particular foldMap (foldMap f)
seems a relatively complex outcome?
Sorry, I think the name
Move concatMap out
was not so good after all. For example, it's not like incatMaybes (concatMap f x) ==> concatMap (catMaybes . f) x
theconcatMap
-call is afterwards "outside" acatMaybes
call.The new names proposed now instead emphasize the function that is moving from outside into the higher-order argument of
concatMap
. A bit in the spirit of the name of this existing hint: https://github.com/ndmitchell/hlint/blob/e05030a08b238ff4d196338d01be1db37e891341/data/hlint.yaml#L122