Skip to content

Conversation

@jgardella
Copy link
Contributor

Adds a new rule to disallow partial functions. The rule will suggest to use non-partial functions or pattern matching instead.

| PatternMatch
| Function of functionName:string

let private partialFunctionIdentifiers =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krzysztof-Cieslak I added all the partial collection functions that I'm aware of, anything else we should add?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgardella how about Map.Item -> Map.TryFind

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knocte At the moment it'll require a little bit more work to handle methods on an object instance (some type checking) - might be worth another PR for that, we could potentially add:

Map.find -> Map.tryFind
Map.findKey -> Map.tryFindKey

@knocte
Copy link
Collaborator

knocte commented Jan 2, 2021

who needs to review this? would be nice to get it merged

@duckmatt duckmatt marked this pull request as ready for review January 8, 2021 00:51
@duckmatt
Copy link
Collaborator

duckmatt commented Jan 8, 2021

Just tried to resolve the conflicts in the Github UI, was not a good idea 😅

@duckmatt
Copy link
Collaborator

duckmatt commented Jan 8, 2021

@knocte Looks good to go in.

Potentially worth considering having these be hints although there is the downside which is that we'd lose the applicable documentation page

@duckmatt duckmatt merged commit 10662ae into fsprojects:master Jan 8, 2021
knocte pushed a commit to knocte/FSharpx.Collections that referenced this pull request Sep 6, 2021
FSharpLint's new recently added rule[1] complains about
function Seq.tail being a partial function, so we need
an alternative before all try-prefixed versions get
included in FSharp.Core[2]. This is not actually a
tryTail function but at least most uses of Seq.tail
use a Seq.head before it, so we can replace both calls
to Seq.(try)head & Seq.tail with a single-call to this
Seq.tryHeadTail which shouldn't be considered a partial
function anymore (even if it calls Seq.tail underneath).

Adding it in FSharpx.Collections would be a nice stopgap
instead of having to include this function in every F#
project that wants to enable this new FSharpLint rule.

[1] fsprojects/FSharpLint#453
[2] fsharp/fslang-suggestions#803
knocte pushed a commit to knocte/FSharpx.Collections that referenced this pull request Sep 6, 2021
FSharpLint's new recently added rule[1] complains about
function Seq.tail being a partial function, so we need
an alternative before all try-prefixed versions get
included in FSharp.Core[2]. This is not actually a
tryTail function but at least most uses of Seq.tail
use a Seq.head before it, so we can replace both calls
to Seq.(try)head & Seq.tail with a single-call to this
Seq.tryHeadTail which shouldn't be considered a partial
function anymore (even if it calls Seq.tail underneath).

Adding it in FSharpx.Collections would be a nice stopgap
instead of having to include this function in every F#
project that wants to enable this new FSharpLint rule.

[1] fsprojects/FSharpLint#453
[2] fsharp/fslang-suggestions#803
knocte pushed a commit to knocte/FSharpx.Collections that referenced this pull request Sep 17, 2021
FSharpLint's new recently added rule[1] complains about
function Seq.tail being a partial function, so we need
an alternative before all try-prefixed versions get
included in FSharp.Core[2]. This is not actually a
tryTail function but at least most uses of Seq.tail
use a Seq.head before it, so we can replace both calls
to Seq.(try)head & Seq.tail with a single-call to this
Seq.tryHeadTail which shouldn't be considered a partial
function anymore (even if it calls Seq.tail underneath).

Adding it in FSharpx.Collections would be a nice stopgap
instead of having to include this function in every F#
project that wants to enable this new FSharpLint rule.

[1] fsprojects/FSharpLint#453
[2] fsharp/fslang-suggestions#803
knocte pushed a commit to knocte/FSharpx.Collections that referenced this pull request Sep 17, 2021
FSharpLint's new recently added rule[1] complains about
function Seq.tail being a partial function, so we need
an alternative before all try-prefixed versions get
included in FSharp.Core[2]. This is not actually a
tryTail function but at least most uses of Seq.tail
use a Seq.head before it, so we can replace both calls
to Seq.(try)head & Seq.tail with a single-call to this
Seq.tryHeadTail which shouldn't be considered a partial
function anymore (even if it calls Seq.tail underneath).

Adding it in FSharpx.Collections would be a nice stopgap
instead of having to include this function in every F#
project that wants to enable this new FSharpLint rule.

[1] fsprojects/FSharpLint#453
[2] fsharp/fslang-suggestions#803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants