question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linq mutator proposal

See original GitHub issue

I’m thinking about a cool new mutator for C#. There are a lot of LinQ methods that return the same interface, this makes them suitable for removing and switching. For example:

var query = someList.Where(x => x.Name == "Stryker").Distinct();
var query = someList.Where(x => x.Name == "Stryker"); // mutated

And

var query = someList.Where(x => x.Name == "Stryker").Reverse();
var query = someList.Where(x => x.Name == "Stryker"); // mutated

And

var query = someList.Where(x => x.Name == "Stryker").SingleOrDefault();
var query = someList.Where(x => x.Name == "Stryker").FirstOrDefault(); // mutated

What do you guys thinks about a mutator like this? Would this be useful, and if so, what kind of mutations should we make?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
richardwerkmancommented, Oct 7, 2018

So to further refine the issue, I suggest the following mutations:

Original Mutated
Distinct()
Reverse()
OrderBy()
OrderByDescending()
SingleOrDefault() FirstOrDefault()
FirstOrDefault() SingleOrDefault()
First() Last()
Last() First()
All() Any()
Any() All()
Skip() Take()
Take() Skip()
SkipWhile() TakeWhile()
TakeWhile() SkipWhile()
Min() Max()
Max() Min()
Sum() Count()
Count() Sum()
1reaction
richardwerkmancommented, Oct 7, 2018

@Michielpeeters No the mutations are not specific for Linq statements with Where, that was just an example query. I’m not mutating Where in the Linq mutator with reason because the expression in the Where() will already be mutated by Stryker. An example on how this mutator will work is:

var query = someList.Distinct().OrderBy(x => x.Age);

would be mutated into

var query = someList.OrderBy(x => x.Age);

and

var query = someList.Distinct();

When you are sure your tests are correct and still no test fails when removing .Distinct() for example, maybe the .Distinct() can be safely removed from your codebase. That way the mutation was still useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Equivalent to NEW operator that uses mutators instead of ...
Short Answer No you can not use mutators in JPQL. While I do not know LINQ I can not see this getting done...
Read more >
Modernize Your C# Code - Part I: Properties
Actually, the idea of a mutator method (getter / setter) for a field is as ... A great feature in C# 3 has...
Read more >
Dynamic filtering and sorting with Entity Framework
It is supposed to 'mutate' the query by applying a LINQ operator to it, ... SearchFieldMutators = new List<SearchFieldMutator<UserListItem, ...
Read more >
Containers and Aggregates, Mutators and Isolates for ...
Containers and Aggregates, Mutators and Isolates for Reactive Programming. Aleksandar Prokopec ... We propose reactive isolates for concurrent reactive pro-.
Read more >
Time to open up a can of worms: LINQ
LINQ enables type safe querying as a first-class construct from any ... terms, when I offer solutions to the very issue that the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found