fsprojects / fsprojects/FSharpLint
Suggestion : Detect `[Type].map f |> [Type].choose g` and propose change to `[Type].choose (f >> g)`
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 327
- Forks
- 74
- PR merge metrics
- No merged PRs in 30d
Description
Description
Since choose does a map plus filter operation, any preceding map can be coalesced, especially in the all too common case where g is the built-in function id.
Repro steps
Code looking like
foldername :: (Seq.toList symbolFolders)
|> Seq.map (I.getSymbolsByFolder filename)
|> Seq.choose id
|> Seq.tryFind (I.symbolMatch tokens)
Would-be-nice behavior
Hint to the effect that
foldername :: (Seq.toList symbolFolders)
|> Seq.choose (I.getSymbolsByFolder filename)
|> Seq.tryFind (I.symbolMatch tokens)
would be simpler
Actual behavior
No such hint
Known workarounds
Manual check/code review
Related information
FWIW, latest tool release under dotnet 7.0.302 on Windows 10 Home
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation file or test; start by locating FSharpLint's existing rule for redundant or coalescible Seq operations. Use the reported Seq.map followed by Seq.choose pattern as the reproduction, and consider the work done when the requested hint appears for that pattern without changing unrelated pipelines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100