Logo ionide-analyzers

ListEqualsEmptyListAnalyzer

Problem

It is less performant to check if a list is empty by using the = operator.

let a = [ 1; 2; 3 ]
// Analyzer will trigger
let b = [] = a

Fix

let b = List.isEmpty a // will check if there is no tail which is faster than the equality check.

Code fix

This analyzer has a code fix for Ionide:

Code fix for ListEqualsEmptyList

val a: int list
val b: bool
Multiple items
module List
from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | op_Nil
  | op_ColonColon of Head: 'T * Tail: 'T list
  interface IReadOnlyList<'T>
  interface IReadOnlyCollection<'T>
  interface IEnumerable
  interface IEnumerable<'T>
  member GetReverseIndex: rank: int * offset: int -> int
  member GetSlice: startIndex: int option * endIndex: int option -> 'T list
  static member Cons: head: 'T * tail: 'T list -> 'T list
  member Head: 'T
  member IsEmpty: bool
  member Item: index: int -> 'T with get
  ...
val isEmpty: list: 'T list -> bool

Type something to start searching.