Skip to content

Simplify some collection queries #1

@ranma42

Description

@ranma42

The following expressions are equivalent (the arrow describes the preferred direction):

No-op:

  • source.Skip(0) -> source
  • source.Where(true) -> source

Absorb:

  • source.Take(0).* -> source.Take(0)
  • source.Take(0) -> whatever.Take(0)
  • source.Where(false) <-> source.Take(0)

Commutativity:

  • source.OrderBy(x).Where(y) <-> source.Where(y).OrderBy(x)
  • source.Where(x).Distinct() <-> source.Distinct().Where(x)

Simplifications:

  • source.Where(x).Where(y) -> source.Where(x && y)
  • source.OrderBy(x).OrderBy(y) -> source.OrderBy(y)
  • source.Take(x).Take(y) -> source.Take(Min(x, y)) Optimize multiple consecutive LIMITs dotnet/efcore#35384
  • source.Skip(x).Skip(y) -> source.Skip(Max(x, 0) + Max(y, 0))
  • source.Take(x).Skip(y) -> source.Skip(y).Take(Max(x, 0) - Max(y, 0))

Operations on singletons:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions