fsprojects / fsprojects/FSharpLint

Suggestion : Detect `[Type].map f |> [Type].choose g` and propose change to `[Type].choose (f >> g)`

Open
#600 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.